I am trying to send an email with another host and every time I got this error-> Mailer Error: SMTP connect() failed
. Here is my code
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = ' host IP ';
$mail->Port = 587;
$mail->SMTPSecure = 'ssl'; // I had also tried with TLS
$mail->SMTPAuth = true;
$mail->Username = "my@username.com";
$mail->Password = "password";
$mail->setFrom('my@username.com', 'MY Personal');
$mail->addAddress($To);
if($MoreAddresses != "")
{
foreach($MoreAddresses as $Address)
{
$mail->addAddress($Address);
}
}
$mail->Subject = $Subject;
$mail->msgHTML($Body);
$mail->AltBody = 'This email contains HTML contents.';
if($MoreAddresses != "")
{
foreach($MoreAddresses as $Address)
{
$mail->addAddress($Address);
}
}
$mail->Subject = $Subject;
$mail->msgHTML($Body);
$mail->AltBody = 'This email contains HTML contents.';
if (!$mail->send())
{
return "Mailer Error: " . $mail->ErrorInfo;
}
else
{
return "Message sent!";
}
I had tried with many of question but couldn't help me well.
答案 0 :(得分:1)
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "myemail@gmail.com";
$mail->Password = "**********";
$mail->Port = "465";
这是一个有效的配置。 尝试替换你拥有的东西
答案 1 :(得分:1)
此邮件的代码
$to = "".$_REQUEST['txtphp_to']."";
$subject = "Nullam id dolor id nibh ultricies vehicula.";
$txt = "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.
Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam id dolor id nibh ultricies vehicula.";
$headers = "From: $s_emailid" . "\r\n";// .
if(mail($to,$subject,$txt,$headers))
{
echo "done";
}
else
{
echo "error";
}
答案 2 :(得分:0)
使用时
$mail->Port = 587;
$mail->SMTPSecure = 'ssl';
然后端口是:tls = 587,ssl = 465。
答案 3 :(得分:0)
添加mail.php使用下面的代码,它对我来说很好......
include "../Mail/Mail.php";
$from = "test<emai>";
$to = $toname."<".$tomail.">";
$subject = $subject;
$body =$body;
$host ="ssl://smtp.gmail.com";
$port = "465";
$username = "test@gmail.com";
$password = "123456";
$headers['From'] =$from;
$headers['To'] = $to;
$headers['Bcc'] = $from;
$headers['Subject'] = $subject;
$headers['Reply-To'] = 'no-replay<no-replay>';
$smtp = Mail::factory('smtp',
array ('host' => $host, 'port' => $port,
'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail))
{
$mail->getMessage() ;
}