【问题标题】:Sending email with phpmailer, receiving a SMTP error使用 phpmailer 发送电子邮件,收到 SMTP 错误
【发布时间】:2013-12-04 11:54:54
【问题描述】:

在我的网站上,我有一个简单的联系表,但我不知道为什么我不能发送电子邮件。

HTML:

<form id="contactForm" method="post"  action="js/sendmail.php" >
  <fieldset>
     <p><label for="name" class="label">Name*:</label>
     <input type="text" name="name" id="Text1" class="input required"  />                                        
     </p>
     <p><label for="email" class="label">Email*: </label>
      <input type="email" name="email" id="contact_email" class="input email required"  />  
      <span class="input_feedback"></span>                                      
     </p>          
     <p>
      <label class="label">Your message*: </label>
      <textarea class="textarea required" name="message" rows="10" cols="50"  ></textarea>
     </p>
     <p class="submitButtons">
      <input type="submit" value="Send email" id="senEmail"    class="button"/>   
     </p>                      
  </fieldset>
</form>

PHP:

<?php
include('class.phpmailer.php');
include("class.smtp.php"); 
session_set_cookie_params('3600'); // 1 hour
session_start();
$mail->SMTPSecure = "ssl"; 
$mail->SMTPKeepAlive = true;  
$mail->Mailer = "smtp"; 
$mail = new PHPMailer(); // create a new object
$mail->SMTPDebug =2;
$mail->IsSMTP(); // send via SMTP
$mail ->Host = 'mrvnet.kundenserver.de';       
$mail->Port= 465;
$mail->SMTPAuth = true;
$mail->Username = 'info@brightongatwicktransfer.com';
$mail->Password = '******';
$mail->SetFrom('myName@yahoo.com');
$mail->Subject = "Test";
$mail->Body = "Something";
$mail->AddAddress('info@brightongatwicktransfer.com');
if(!$mail->Send())
{ echo "Mailer Error: " . $mail->ErrorInfo;}
else
{ echo "Message has been sent";}
?>

我尝试了 'ssl' 和 'tls' 但没有结果。

主机公司说主机是正确的,并要求我尝试使用 587 和 25 端口,但我总是收到同样的错误:

2013-12-04 11:40:00 SMTP 错误:无法连接到服务器:连接尝试
由于连接方在一段时间后没有正确响应而失败,或 建立连接失败,因为连接的主机没有响应。 (10060) SMTP 连接()失败。邮件程序错误:SMTP 连接()失败。

【问题讨论】:

    标签: phpmailer


    【解决方案1】:

    不是 PHP 编码器,但在这里:

    $mail->SMTPSecure = "ssl"; 
    $mail->SMTPKeepAlive = true;  
    $mail->Mailer = "smtp"; 
    $mail = new PHPMailer(); // create a new object
    

    你在分配对象你使用它之后,这是无效的,你应该先分配它:

    $mail = new PHPMailer(); // create a new object
    $mail->SMTPSecure = "ssl"; 
    $mail->SMTPKeepAlive = true;  
    $mail->Mailer = "smtp"; 
    

    【讨论】:

    • 谢谢,但现在我得到了:2013-12-04 12:41:02 SMTP 错误:无法连接到服务器:无法找到套接字传输“ssl” - 您是否忘记启用它时你配置了PHP? (4104) SMTP 连接()失败。邮件程序错误:SMTP 连接()失败。
    • 谢谢,刚刚从我的主机收到一封电子邮件,由于其固定设置的限制,在我们的共享主机中无法通过 php 脚本发送 smtp。我们强烈建议您使用 php mail 或 asp mail'
    猜你喜欢
    • 1970-01-01
    • 2011-04-06
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    • 2015-06-13
    • 1970-01-01
    • 2021-04-04
    相关资源
    最近更新 更多