0
votes

I'm ripping my head off in a moment...

Using PHPmailer to send a email from my site. I have created a HTML-form on my website, and the values from there needs to go to my mail... You know - standard :)

But I keep getting this error : Mailer Error: SMTP connect() failed.

When I have turned SMTPDEBUG on it goes like this: SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

The host and port is correct, got the details from my provider.. Is there something i'm missing, typed in wrong or misunderstood?

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  // here we use the php mail function
  // to send an email to:
  // [email protected]
  mail( "[email protected]", "Feedback Form Results",$message, "From: $email" );

require 'PHPMailer/class.phpmailer.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.test.com';                      // Specify main and backup server
$mail->Port = 25;
$mail->SMTPDebug  = 2;  
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                            // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted

$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
//$mail->addAddress('[email protected]', 'Josh Adams');  // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional
//$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

$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';

?>
1
Of course i getting the mail when I have typed mail( "[email protected]", "Feedback Form Results",$message, "From: $email" ); But now i'm just not recving the mail...user2254488

1 Answers

0
votes

From my understanding the 'ssl' setting for SMTPSecure is for direct ssl connect, while the 'tls' setting is for plain connect followed by upgrading to SSL with the STARTTLS command. With port 25 you need plain connect, e.g. 'tls'.