2

I'm new in Php and find a Php mailer class to send email but getting following error.

Error Message:

Message was not sent.Mailer error: SMTP connect() failed. 

Php Code:

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "smtp.impeccableplus.com"; // SMTP server

$mail->From     = "from@example.com";
$mail->AddAddress("email@gmail.com");

$mail->Subject  = "First PHPMailer Message";
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}

?>

Thanks.

Update:

I just change the host name = localhost. Now it's successfully sent email but problem is, It's showing the mail in spam folder. Why ?

Babu
  • 455
  • 2
  • 14
  • 33
  • 3
    Something went wrong. PHPMailer has a `SMTPDebug` option. [Debugging PHP Mail() and/or PHPMailer](http://stackoverflow.com/q/2896280) – Pekka Jan 27 '14 at 04:25
  • check your mail server credential too – Emilio Gort Jan 27 '14 at 04:26
  • @Pekka웃 I just change the host name = localhost. Now it's successfully sent email but problem is, It's showing the mail in spam folder. Why ? and showing sender name = root user, why ? – Babu Jan 27 '14 at 04:32
  • [From issue](http://stackoverflow.com/questions/13918999/how-to-change-envelope-sender-address-using-phpmailer) – Emilio Gort Jan 27 '14 at 04:42
  • 1
    [spam issue](http://stackoverflow.com/questions/16717257/phpmailer-mails-going-straight-to-spam) – Emilio Gort Jan 27 '14 at 04:43
  • When you change to sending through localhost, you are no longer using your upstream mail server, you probably have zero sending reputation, so you're likely to get marked as spam. Also if you're sending via localhost, you don't need to use SMTP - call `IsMail()` instead of `IsSMTP()`. – Synchro Jun 13 '14 at 09:41

1 Answers1

1

There could be a number of reasons for this:

  • Your SMTP server smtp.impeccableplus.com could be blacklisted. You can check if your SMTP server is being blacklisted
  • The from address could be regarded as spammy, especially if you're using from@example.com
  • Some mail clients (such as Gmail) do not like the fact that you are sending an email "from" someone else's address if it really didn't originate from that address
  • and possibly 20+ other reasons

You should consider setting up SPF and DKIM for your email address that you are sending emails from. Read this and this. By Setting up SPF and DKIM, you are essentially authenticating the email which considerably improves mail delivery.

Alternatively, if you really get stuck, consider using a mail delivery API such as Sendgrid.

Nick Duncan
  • 829
  • 6
  • 17