0

I am having trouble sending an email with phpmailer. I am confused at what SMTP username and password are? Does that have to be myn? I have created a script but it does not work as expected.

My page keeps saying

"Message could not be sent.Mailer Error: SMTP connect() failed."

Here is my code:

<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'jswan';                            // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also     accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('josh@example.net', 'Josh Adams');  // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$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;
   exit;
}

echo 'Message has been sent';
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
user3626795
  • 21
  • 1
  • 4
  • It simple means your host/username/password/smtpsecure data are wrong. Maybe you should also set other Port ? Double check your data and SMTPSecure settings – Marcin Nabiałek May 12 '14 at 14:41
  • I have changed my smtp details to smtp.hotmail.com and the username and password to my account details. But is the username your email? Im still getting the same error – user3626795 May 12 '14 at 14:46
  • yes, the SMTP user name is your email id and password is your email's password. Also add the smptp port. – Janaki May 12 '14 at 15:15

0 Answers0