使用G Suit的cpanel中的PHP邮件功能不起作用

时间:2019-03-14 10:35:26

标签: cpanel

我想通过电子邮件提交表单,但是PHP邮件功能在hostgator云服务器中不起作用,我在此服务器上使用了G Suit。请帮助

1 个答案:

答案 0 :(得分:0)

您可以使用PHPMailer代替服务器邮件,因为从php发送电子邮件在大多数主机提供商中不起作用,因此PHPMailer解决了您的问题,因为您可以通过php从SMTP发送电子邮件

<?php
    require 'PHPMailerAutoload.php';
    $mail = new PHPMailer;
    //Enable SMTP debugging. 
    $mail->SMTPDebug = 3;                               
    //Set PHPMailer to use SMTP.
    $mail->isSMTP();            
    //Set SMTP host name                          
    $mail->Host = "smtp.gmail.com";
    //Set this to true if SMTP host requires authentication to send email
    $mail->SMTPAuth = true;                          
    //Provide username and password     
    $mail->Username = "name@gmail.com";                 
    $mail->Password = "super_secret_password";                           
    //If SMTP requires TLS encryption then set it
    $mail->SMTPSecure = "tls";                           
    //Set TCP port to connect to 
    $mail->Port = 587;                                   
    $mail->From = "name@gmail.com";
    $mail->FromName = "Full Name";
    $mail->addAddress("name@example.com", "Recepient Name");
    $mail->isHTML(true);
    $mail->Subject = "Subject Text";
    $mail->Body = "<i>Mail body in HTML</i>";
    $mail->AltBody = "This is the plain text version of the email content";
    if(!$mail->send())  {
       echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message has been sent successfully";
    }
?>

PHPMailer文档https://github.com/PHPMailer/PHPMailer/wiki/Tutorial