Skip to content
Advertisement

PHPMailer sent but Not received

I am using PHPMailer, it seems works but not received any message from them I don’t know what is wrong.

I’m using tester email address from this site. Mail Tester

here is my code.

contact-form.php

<?php

$msg = '';

if (array_key_exists('email', $_POST)) {
date_default_timezone_set('Etc/UTC');

require 'php-mailer/PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = 25;

$mail->setFrom('noreply@****.com', 'Sender Name');

$mail->addAddress('web-0zlvk@mail-tester.com', 'Recipient Name');

if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
    $mail->Subject = 'Message from '.$_POST['name'];
    $mail->isHTML(true);
    $mail->CharSet = 'UTF-8';
    $mail->Body = <<<EOT
    Email: {$_POST['email']}
    Name: {$_POST['name']}
    Message: {$_POST['message']}
   EOT;
if(!$mail->send()) {
   $arrResult = array ('response'=>'error');
}

  $arrResult = array ('response'=>'success');

  echo json_encode($arrResult);

} else {

  $arrResult = array ('response'=>'error');
  echo json_encode($arrResult);

  }
 }
?>

PHPMailerAutoload.php

<?php
function PHPMailerAutoload($classname)
{
$filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
if (is_readable($filename)) {
    require $filename;
  }
}

if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
    spl_autoload_register('PHPMailerAutoload', true, true);
} else {
    spl_autoload_register('PHPMailerAutoload');
}
} else {
function __autoload($classname)
{
    PHPMailerAutoload($classname);
 }
}

When I click Send Message I can see “Your message has been sent to us” but I won’t receive any message from them.

Advertisement

Answer

First up, you’re using an old version – get the latest.

You’re using SMTP to localhost, which means you’re running a local mail server. That’s a good configuration, but means that your script only knows about delivery to your local server, and not beyond that to its final destination. To find out what happens after that you need to go and look at your mail server logs, usually somewhere like /var/log/mail.log.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement