0

i cant send email using the php mailer class. here is the error i am getting.

Error

Mailer Error: The following From address failed: admin@mobilebitzltd.com : Called Mail() without being connected.

here is the code i am using.

$mail = new PHPMailer();
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.live.com'; // Specify main and backup server
$mail->Port = '465';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'admin@mydoamin.com'; // SMTP username
$mail->Password = 'sdf'; // SMTP password
$mail->SetFrom($from, $from);
$mail->AddReplyTo($from, $from);
$mail->Subject = $subject;
$mail->MsgHTML($message);
$address = $to;
$mail->AddAddress($address, $customer_name);

if (!$mail->Send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
}
else
{
    echo "Message sent!";
    exit;
}
message
  • 4,513
  • 2
  • 28
  • 39
wahab
  • 51
  • 1
  • 9

2 Answers2

0

I would recommend putting the whole mail process into a try / catch block to get more information about the error as a good place to start. There could be more details in the exception which could help pinpoint the problem.

try {
    $mail->SetFrom($from, $from);
    ...
    ...
    $mail->Send();
} catch ( phpmailerException $e ) {
    echo $e->errorMessage(); 
} catch ( Exception $e ) {
    echo $e->getMessage(); 
}

I found anther question that may be of some help which may be worth looking over: Having trouble with PHPMailer

Most of all, I think its important someone point out you just posted your plain text password on the internet. You may want to change it as quickly as possible everywhere it is used.

Community
  • 1
  • 1
0

Add

$mail->SMTPDebug = 1; 

to get more information on what went wrong.

And try

$mail = new PHPMailer; 

at the top.

Andrei Nicusan
  • 4,555
  • 1
  • 23
  • 36
Burpy Burp
  • 459
  • 3
  • 12
  • Hints from here may help your problem. [PHPMailer tutorial](http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html#External_SMTP_Servers_PHP_Mail) – Burpy Burp Dec 07 '13 at 16:46