【问题标题】:PHP send mail error 3PHP发送邮件错误3
【发布时间】:2017-06-07 09:58:47
【问题描述】:

当我尝试在我的网站上发送表单时,我收到了这个错误:

对不起...,我的邮件服务器似乎没有响应。请稍后再试!

我的东西是我的 contact_me.php 文件

有代码

<?php
  // Check for empty fields
  if(empty($_POST['name'])          ||
     empty($_POST['email'])         ||
     empty($_POST['phone'])         ||
     empty($_POST['message'])   ||
     !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
  {
     echo "No arguments Provided!";
     return false;
  }

  $name = strip_tags(htmlspecialchars($_POST['name']));
  $email_address = strip_tags(htmlspecialchars($_POST['email']));
  $phone = strip_tags(htmlspecialchars($_POST['phone']));
  $message = strip_tags(htmlspecialchars($_POST['message']));

  error_reporting(E_STRICT);

  date_default_timezone_set('Portugal/Lisbon');

  require_once('class.phpmailer.php');

  $mail = new PHPMailer();

  $mail->IsSMTP(); // telling the class to use SMTP
  $mail->Host       = "a.a.pt"; // SMTP server
  $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->Host       = "a.a.pt"; // sets the SMTP server
  $mail->Port       = 25;                    // set the SMTP port for the GMAIL server
  $mail->Username   = "a@a.pt"; // SMTP account username
  $mail->Password   = "a";        // SMTP account password

  $mail->SetFrom('a@a.pt', 'First Last');

  $mail->AddReplyTo("a@a.pt","First Last");

  $mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";

  $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

  $address = "a@a.pt";
  $mail->AddAddress($address, "a@a.pt");



  $formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
  $formcontent= eregi_replace("[\]",'',$formcontent);
  $mail->MsgHTML($formcontent);


  if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
  } else {
           echo "Message sent!";
         }
?>

【问题讨论】:

    标签: php email sendmail


    【解决方案1】:

    您可以尝试使用我的课程,我相信这可以 100% 运行,即使它对您不起作用是凭据问题或电子邮件服务器由于某种原因浪费了连接

    class Mailplus{
        protected  $host = "ssl://smtps.*.com";
        protected $port = "123";
        protected $username = "email@example";
        protected $password = "*";
        protected $from = "Email from - Name <email@example>";
        protected $smtp;
        function __construct() {
            require_once "Mail.php";
            $this->smtp = Mail::factory('smtp',
                array ('host' => $this->host,
                    'port' => $this->port,
                    'auth' => true,
                    'username' => $this->username,
                    'password' => $this->password));
        }
    
        function SendMail($to ,$subject,$body){
            $headers = array ('From' => $this->from,
                'Subject' => $subject,
                'MIME-Version' =>'1.0',
                'Content-Type' =>'text/html',
                'charset' => 'ISO-8859-1');
            $mail = $this->smtp->send($to, $headers, $body);
            if (PEAR::isError($mail)) {
                return "Ex_001";
            } else {
                return true;
            }
        }
    }
    

    然后使用这个命令

    $mail = new Mailplus (); 
    if ($mail.SendMail("to@example.com","Subject","html emial")==ture){
       //email sent
    else{
       //email not sent
    }
    

    【讨论】:

    • 将类放在一个php文件中,在应该发送电子邮件的页面上模仿一个include_once('folder / mymailclass.php');在将通过电子邮件发送给您的页面上,输入: $mail = new Mailplus();使用此功能后 Mailplus.SendMail(....);这返回 true 或 Ex_001(不发送);
    • 显然记得用你的 SMTP 服务器数据配置类
    • 现在它显示“您的消息已发送”。但我没收到
    • 该类工作,使用 PEAR :: isError 得到各种错误,如果你告诉她这意味着它与服务器通信并设法向他们发送电子邮件。需要是smtp服务改写邮件失败的问题
    • 我认为我做错了。接收邮件的邮箱应该放在哪里?
    猜你喜欢
    • 2010-10-18
    • 2015-09-14
    • 1970-01-01
    • 2018-10-11
    • 2012-05-18
    • 1970-01-01
    • 2016-08-30
    • 2014-03-16
    • 1970-01-01
    相关资源
    最近更新 更多