Showing posts with label phpmailer. Show all posts
Showing posts with label phpmailer. Show all posts

Thursday, June 26, 2008

PhpMailer Settings to Send email using PHP with Gmail



To work with this just follow this 3 simple step

1. Create a new file and named it any name you like
example: send.php
2. Paste the following code

include "path to your class.phpmailer.php"; // something like this include include "PHPMailer_v2.0.0/class.phpmailer.php";

$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username@gmail.com"; // your SMTP username or your gmail username
$mail->Password = "password"; // your SMTP password or your gmail password
$from = "webmaster@example.com"; // Reply to this email
$to="recepient@domain.com"; // Recipients email ID
$name="Jersey Name"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Sending Email From Php Using Gmail";
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

3. Troubleshooting

If ever a warning message occurs occurs something like this
"Warning: fsockopen()[a href:="function.fsockopen">functionopen]: unable
to connect to ssl://smtp.gmail.com:465(Unable to find the socket transport "ssl" -did you forget to enable it when you configured PHP?)
in ....

To fix this:
Go to your php settings and enable php_openssl

that's it..