Hello, could you please help me out on this?
I can't get my code to send an email. I've tried everything. The mail() command, an external phpmailer class, nothing seems to work ...
I've been looking for 4 hours for this now, and I can't get a simple mail command to work, I really need some help. A working source code would be awesome. This is what I have, and it's not working:
Code:
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "myaccount@gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
$mail->AddReplyTo("mymail@gmail.com","My Name");
$mail->From = "mymail@gmail.com";
$mail->FromName = "test test";
$mail->Subject = "PHPMailer Test Subject via gmail";
//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("reciever@anymail.com", "Computer Addict");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
That's from the class, here's some PHP code that I tried:
Code:
<?
include("Mail.php");
$recipients = "reciever@gmail.com";
$headers["From"] = "my@mail.com";
$headers["To"] = "my@mail.com";
$headers["Subject"] = "Hey!";
$body = "TEST MESSAGE!";
$params["host"] = "smtp.gmail.com";
$params["port"] = "465";
$params["auth"] = true;
$params["username"] = "my@mail.com";
$params["password"] = "mypw";
echo "First Stage";
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory("smtp", $params);
echo "Middle Stage";
// Send the mail off
$mail_object->send($recipients, $headers, $body);
echo "Final Stage";
?>
Now with this code, it does the first and middle stages, but it fails at sending off the mail. The request times out.
Any ideas? Some help would be really appreciated. I can't solve this :/