Wednesday, July 15, 2015

Check if IP address is on spam list

http://www.spamhaus.org/query/bl?ip=x.x.x.x

Send email from cmd

telnet 192.168.x.x 25
HELO
MAIL FROM: root@example.com
RCPT TO: user@example.com
DATA
Subject: TESTING BY ROOT
hello root@example.com from user@example.com
.


Tuesday, July 14, 2015

Send emails from html form


<?php
// this code must be on some.php file on hosting. You can not use this code on localhost PC!
// change webmaster@example.com in what you want!

  if (isset($_REQUEST['to']))  {

  //Email information
  $to= $_REQUEST['to'];
  $from = $_REQUEST['from'];
  $subject = $_REQUEST['subject'];
  $message = $_REQUEST['message'];

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <webmaster@example.com>' . "\r\n";


  //send email
  mail($to, $subject, $message, $headers);

  //Email response
  echo "Thank you for sending email!";
  }

  //if "email" variable is not filled out, display the form
  else  {
?>

 <form method="post">
  From: webmaster@example.com <br />
  To: <input name="to" type="text" /><br />
  Subject: <input name="subject" type="text" /><br />
  Message:<br />
  <textarea name="message" rows="15" cols="40"></textarea><br />
  <input type="submit" value="Submit" />
  </form>

<?php
  }
?>

Send emails from own hosting

<?php

// multiple recipients (note the commas)
$to = "sendtoemailc@yahoo.com";


// subject
$subject = "Nonsensical Latin";

// compose message
$message = "
<html>
  <head>
    <title>Nonsensical Latin</title>
  </head>
  <body>
    <h1>Nonsensical Latin</h1>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
       Nam iaculis pede ac quam. Etiam placerat suscipit nulla.
       Maecenas id mauris eget tortor facilisis egestas.
       Praesent ac augue sed <a href=\"http://lipsum.com/\">enim</a> aliquam auctor.
       Pellentesque convallis tempor tortor. Nullam nec purus.</p>
  </body>
</html>
";

// To send HTML mail, the Content-type header must be set
// compose headers
$headers = "From: webmaster@example.com\r\n";
$headers .= "Reply-To: webmaster@example.com\r\n";
$headers .= "X-Mailer: PHP/".phpversion();


// send email
mail($to, $subject, $message, $headers);
?>

Send emails from Gmail

<?php
//Download ZIP from https://github.com/PHPMailer/PHPMailer
//extract ZIP folder
//Copy folder name:PHPMailer-master in C:\wamp\www, so your path is C:\wamp\www\PHPMailer-master
//create this sendmailfromGmail.php file in C:\wamp\www with this code:

require_once "PHPMailer-master/PHPMailerAutoload.php";
$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';   // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'myaccount@gmail.com';                 // SMTP username
$mail->Password = 'mypassword';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = 'myaccount@gmail.com';
$mail->FromName = 'My name';
//$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('send-to-account@yahoo.com');               // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

?>

What is client IP address?

<?php
// Function to get the client IP address
function get_client_ip() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
       $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

//Execute the function
$ip = get_client_ip();
echo "Your IP is> " . $ip;

?>