电子邮件功能未发送:托管服务器Godaddy

时间:2019-03-27 10:54:31

标签: php email phpmailer

我在php中创建了电子邮件功能,我的文件和所有托管都是Godaddy。 每当我提交我的表单邮件时,如果没有显示错误消息---邮件未成功发送,它将被发送出去。请一些帮助我。 我的PHP功能代码很烂:

<?php
include("/home/mu3c3ezzh1cs/public_html/mailer/class.phpmailer.php");
 if(isset($_POST['submit'])){
  $name         = $_POST['name'];
  $email        = $_POST['email'];
  $mobile       = $_POST['phone'];
  $location     = $_POST['location'];
  $decs         = $_POST['desc'];
  $contact_name ="Please check the Requirement";
  $message = "";
  $subject_thankyou = "Enquiry Acknowledgement from abc.";
  $message_thankyou = "<p>Dear ".$name.",</p><p>We just received your enquiry. We will get back to you as soon as possible. Thank you for the interest shown on .</p><p>Best Regards<br /> abc<br/> Web :<a href='http://abc.in'>www.abc.in</a></p>";
  $mail = new PHPMailer;
  $mail->IsSMTP(); // enable SMTP
  $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
  $mail->SMTPAuth  = true;  // authentication enabled
  $mail->SMTPSecure = 'ssl';
  $mail->Host     = "hostname";/*Specify main and backup SMTP servers*/
  $mail->Port     = 465;
  $mail->SMTPAuth = true;/*Enable SMTP authentication*/
  $mail->Username = "username";/*SMTP username*/
  $mail->Password = "password";/*SMTP password*/
  $mail->setFrom('info@abd.com', 'abc');
  $mail->addAddress($email , $name);
  $mail->isHTML(true);
  $mail->Subject = $subject_thankyou;
  $mail->Body    = $message_thankyou;
  $mail->AltBody = $subject_thankyou;
  $mail->send();
  $subject ='Enquiry for abc'; 

  $email_header ='<html style="color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); max-width: 575px; line-height: 18px; font-size: 12px; font-family: Arial, Helvetica, sans-serif;">
                    <head>
                      <meta name="viewport" content="width=device-width" />
                      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                  </head>
                  <body bgcolor="#FFFFFF" text="#000000"  style="color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); max-width: 575px; line-height: 18px; font-size: 12px; font-family: Arial, Helvetica, sans-serif;">
                  <table style="font-family:Helvetica,Arial,sans-serif;background:#EFEDED;padding:0 0 10px 0;" cellpadding="0" cellspacing="0" bgcolor="#EFEDED" border="0" width="100%">
                  <tbody>
                  <tr>
                  <td align="center">
                  <table width="96%" cellpadding="0" cellspacing="0"border="0">
                  <tbody>              
                  <tr>
                  <td style="border-top:5px solid #1e96d3;background:#fff;margin:0; padding:20px; border-spacing:0px;">';

  $email_footer = '</td>
                    </tr>               
                    </tbody>
                    </table>
                    </td>
                    </tr>
                    </tbody>
                    </table>
                    </td>
                    </tr>              
                    </tbody>
                    </table>
                    </body>
                    </html>';

    $body = $email_header.
        '<table width="100%" cellpadding="0" cellspacing="0">
              <tr>
              <td style="margin:0; padding:0px 0px 15px 0px; border-spacing:0px;">
              <p style="font-size:14px; color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif; font-weight: bold; line-height: 1.5em; margin: 0px; padding: 0.4em; text-align: left;">
              '.$subject.'
              </p>
              </td>
              </tr>
              <tr>
              <td style="margin:0; padding:0px 0px 15px 0px; border-spacing:0px;">
              <p style="color:#000; font-size:13px; margin:0; font-family:Arial, Helvetica,sans-serif;">
              <strong>
              '.$contact_name.',
              </strong>
              <br>
              </p>
              </td>
              </tr>                     
              <tr>
              <td style="margin:0; padding:0 0 5px 0;">
              <p style="font-size:13px; background-color: rgb(234, 234, 234); color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif; font-weight: bold; line-height: 1.5em; margin: 0px; padding: 0.4em; text-align: left;">
              Details:
              </p>
              </td>
              </tr>
              <tr>
              <td style="margin:0; padding:0px 0px 15px 0px; border-spacing:0px;">
              <table style="font-family:Helvetica,Arial,sans-serif; font-size:12px; font-weight:bold; margin-top:10px; width:100%">
              <tbody>
              <tr>
              <td style="width:120px; padding:4px 0;">
              Name
              </td>  
              <td style="padding-right:10px;">
              :
              </td>
              <td style="font-weight:normal;">
              '.$name.'
              </td>
              </tr>
              <tr>
              <td style="padding:4px 0;">
              Phone Number
              </td>
              <td>
              :
              </td>
              <td style="font-weight:normal;">
              '.$mobile.'
              </td>
              </tr>
        <tr>
              <td style="padding:4px 0;">
              Email
              </td>
              <td>
              :
              </td>
              <td style="font-weight:normal;">
              '.$email.'
              </td>
              </tr>
        <tr>
              <td style="padding:4px 0;">
              Location
              </td>
              <td>
              :
              </td>
              <td style="font-weight:normal;">
              '.$location.'
              </td>
              </tr>
              <tr>
              <td style="padding:4px 0;">
              Description
              </td>
              <td>
              :
              </td>
              <td style="font-weight:normal;">
              '.$decs.'
              </td>
              </tr>
              </tbody>
              </table>
              </td>
              </tr>
              </table>'
              .$email_footer;
    $message .= $body;
    $mail = new PHPMailer;
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;
    $mail->SMTPSecure= false;  
    $mail->Host     = "hostname";
    $mail->Port     = 465;
    $mail->SMTPAuth = true;/*Enable SMTP authentication*/
    $mail->Username = "username";
    $mail->Password = "password";
    $mail->setFrom('info@abc.com', $name);
    $mail->addAddress('abc@gmail.com' , 'abc');
    $mail->isHTML(true);

  if(!$mail->Send()) {
            ?>
                  <script type="text/javascript">
                   window.alert("mail not sent successfully!");
                  // window.location.href="thanks.php";
                </script>
                 <?php
          }
           else{
         ?>
              <script type="text/javascript">
               window.location.href="thanks.php";
            </script>
             <?php
       }
     }
?>

1 个答案:

答案 0 :(得分:0)

问题的根源:您正在使用GoDaddy

GoDaddy不允许您通过自己以外的任何邮件服务器发送邮件(通常使用relay.secureserver.net上的邮件服务器)。切换到该方法可以解决一个问题,但又会解决另一个问题:除非通过gmail服务器发送邮件,否则您不能从发送 gmail地址。他们的SPF规则不允许这样做,并且您的邮件中不会包含gmail的DKIM签名。这意味着您的邮件实际上是伪造的,这就是为什么您看到此类警告的原因-坦白地说,我很惊讶它们的到来。

因此,有两种解决方案:

  1. 当您不使用Gmail服务器时,请勿通过Gmail地址发送邮件;从允许从GoDaddy的服务器发送邮件的域(即您自己的域)发送邮件。
  2. 不要使用GoDaddy;使用不阻止出站SMTP的其他托管服务提供商。

所有这些都在PHPMailer文档中进行了介绍。

与此分开的是,您使用的是错误的且非常脆弱的非常的旧版本的PHPMailer,所以我建议您upgrade,并根据提供的示例创建代码。