2

I am using PHPMailer to send email. It works fine when I use gmail smtp but when I try using my domain smtp what I see on screen is 'message sent!' but I don't receive any email at all. I have tried using debugger, it says

We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. 

and here is my code

<?php
date_default_timezone_set('Etc/UTC');
//Load PHPMailer dependencies
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';

/* CONFIGURATION */
$crendentials = array(
    'email'     => '[email protected]',    
    'password'  => 'xxxxxx'               
    );

$smtp = array(

'host' => 'secure.ehostpk.com',
'port' => 465,
'username' => $crendentials['email'],
'password' => $crendentials['password'],
'secure' => 'ssl' //SSL or TLS

);

/* TO, SUBJECT, CONTENT */
$to         = '[email protected]'; //The 'To' field
$subject    = 'This is a test email sent with PHPMailer';
$content    = 'This is the HTML message body <b>in bold!</b>';



$mailer = new PHPMailer();

//SMTP Configuration
$mailer->isSMTP();
$mailer->SMTPDebug  = 2;
$mailer->SMTPAuth   = true; //We need to authenticate
$mailer->Host       = $smtp['host'];
$mailer->Port       = $smtp['port'];
$mailer->Username   = $smtp['username'];
$mailer->Password   = $smtp['password'];
$mailer->SMTPSecure = $smtp['secure']; 

//Now, send mail :
//From - To :
$mailer->From       = $crendentials['email'];
$mailer->FromName   = 'Team'; //Optional
$mailer->addAddress($to);  // Add a recipient

//Subject - Body :
$mailer->Subject        = $subject;
$mailer->Body           = $content;
$mailer->isHTML(true); //Mail body contains HTML tags

//Check if mail is sent :
if(!$mailer->send()) {
    echo 'Error sending mail : ' . $mailer->ErrorInfo;
} else {
    echo 'Message sent !';
}

I have searched a lot and I don't understand what should I do. Any help would be greatly appreciated.

3
  • Did you check it in you spam or junk folder? Apr 8, 2015 at 12:31
  • 1
    @Sanjay Kumar N S yes, I have checked spam and junk too. Apr 8, 2015 at 12:36
  • I suspect that message is generic, not specific to you - post the whole SMTP transcript. Also you only need to include the autoloader, not the other classes.
    – Synchro
    Apr 8, 2015 at 13:13

1 Answer 1

0

One thing that I have found is, that on most servers these days (especially cpanel servers) the email address you are attempting to send with actually has to be created within cpanel itself in order for it to work properly.

From my understanding, the script only routes it to the server and the email account, and then it's routed further from there and finally sent out from your email account on the server. So a solution may be to actually setup the email address in your server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.