Jarrod
Jarrod

Reputation: 332

PHPMailer doesn't seeem to work on live site, but works on localhost?

I have a PHPMailer script, and I've checked all the other threads that are similar to this, and tried all the solutions that follow the question. But here's the error I'm receiving

2014-01-03 02:25:16 SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Mailer Error: SMTP connect() failed.

And here's my script:

$body = "test";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // I have also tried tls
$mail->SMTPKeepAlive = true;            
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // I have also tried 25
$mail->Username   = "[email protected]";  // GMAIL username
$mail->Password   = "xxxxx";            // GMAIL password

$mail->SetFrom("[email protected]","John  Doe");

$mail->AddReplyTo("[email protected]","John Doe");

$mail->Subject    = "Booking from " . $_POST['person'] . ' at ' . $_POST['name'];

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test


$mail->MsgHTML($body);

$address = "[email protected]";
$mail->AddAddress($address, "John Doe");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

However I just cannot get it to work. I've tried to many different solutions. I'm even happy to use the default php mail however I just need it to send, the php mail wouldn't even get past the hotmail spam filters (by that I mean it didn't even send it to spam).

Any solutions or suggestions here? Thanks a lot!

Upvotes: 1

Views: 2433

Answers (3)

J. Sapar
J. Sapar

Reputation: 11

Just comment this line:

$mail->IsSMTP();

Upvotes: 1

vijay rami
vijay rami

Reputation: 535

Install PHP Mailer From

https://github.com/Synchro/PHPMailer

And Read "A Simple Example"

<?php
require_once('PHPMailer/PHPMailerAutoload.php'); // Load your PHPMailerAutoload.php Correctly Here

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;// debugging: 1 = errors and messages, 2 = messages only                               // 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 = '[email protected]';                 // SMTP username
$mail->Password = '**********';                           // SMTP password
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail  // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;           // or 587                         // TCP port to connect to

$mail->setFrom('[email protected]', 'Vijay Rami');
$mail->addAddress('[email protected]', 'Vijay Rami');     // Add a recipient
//$mail->addAddress('[email protected]');               // Name is optional
//$mail->addReplyTo('[email protected]', 'Information');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');

//$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';
}

Upvotes: 0

jwitt98
jwitt98

Reputation: 1255

Did you make sure your php.ini mail settings are the same on both your live server and your localhost server?

Upvotes: 0

Related Questions