PHPMailer在Godaddy服务器上不起作用

时间:2019-02-23 09:31:11

标签: php email

我已经用PHP开发了一个站点,并为“与我们联系”页面添加了PHPMailer函数,但是该邮件程序功能不起作用。与支持团队联系,但是他们并没有帮助我尝试很多。

<?php
    if(isset($_POST['submit_contact']))  
    {
       require 'PHPMailer/PHPMailerAutoload.php';
       $to = "gmail@gmail.com";
       $name = $_POST['uname'];
       $email = $_POST['email'];
       $phone = $_POST['phonenumber'];
       $companyname = $_POST['companyname'];
       $country = $_POST['country2'];
       $mail = new PHPMailer();
       $mail->isSMTP();                                      
       $mail->SMTPDebug = 2;  
       $mail->SMTPAuth = true;
       $mail->SMTPSecure = 'ssl';
       $mail->Host = "relay-hosting.secureserver.net"; 
       $mail->Port = 465;
       $mail->IsHTML(true);                                     
       $mail->Username = "xxxx@gmail.com";                 
       $mail->Password = "PASSword1@3";   
       $message = array();    
       $message[] = 'Name  :  '.trim($name).' ';        
       $message[]='Phone  :  '.trim($phone).' ';   
       $message[]='Email  :  '.trim($email).' '; 
       $message[]='Company Name  :  '.trim($companyname).' ';    
       $message[]='Country  :  '.trim($country).' ';    
       $message = implode('<br/>', $message);           
       $mail->SetFrom($email);
       $mail->Subject = 'Here is the subject';
       $mail->Body = $message;
       $mail->AddAddress($to); 
       if(!$mail->send()) {
            $msg = "Error while sending email";
            $msgclass = 'bg-danger';
            header("Location: /");
            die();    
       } 
       else {
          $msg = 'A mail with recovery instruction has sent to your email.';
          $msgclass = 'bg-success';
       }     
    }
?>

2 个答案:

答案 0 :(得分:0)

您使用的是gmail,您应将主机设置为smtp.gmail.com,将SMTPSecure设置为ssl,将SMTPAuth设置为true,将端口设置为465,还应使用应用密码,以便您可以看到https://support.google.com/mail/answer/7126229

答案 1 :(得分:0)

$mail = new PHPMailer();
   $mail->isSMTP();                                      
   $mail->SMTPDebug = 1;  
   $mail->SMTPAuth = false;
   $mail->SMTPSecure = 'none';
   $mail->Host = "localhost"; 
   $mail->Port = 25;
   $mail->IsHTML(true);         

解决了SMTP中此更新的问题