电子邮件未从 Byethost 主机发送

Posted

技术标签:

【中文标题】电子邮件未从 Byethost 主机发送【英文标题】:Email Not Sending from Byethost Hosting 【发布时间】:2021-05-07 03:36:19 【问题描述】:

我部署了我的网站,我试图从我的网站发送一封由 Byethost 托管的电子邮件,它显示一条成功消息,但由于某种原因没有收到电子邮件。可能是什么问题?

您将在下面找到 php 脚本。

  <?php

// Replace this with your own email address
$siteOwnersEmail = 'shouman882@gmail.com';


if($_POST) 
    
   $name = trim(stripslashes($_POST['contactName']));
   $email = trim(stripslashes($_POST['contactEmail']));
   $subject = trim(stripslashes($_POST['contactSubject']));
   $contact_message = trim(stripslashes($_POST['contactMessage']));

   // Check Name
    if (strlen($name) < 2) 
        $error['name'] = "Please enter your name.";
    
    // Check Email
    if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]2/is', $email)) 
        $error['email'] = "Please enter a valid email address.";
    
    // Check Message
    if (strlen($contact_message) < 15) 
        $error['message'] = "Please enter your message. It should have at least 15 characters.";
    
   // Subject
    if ($subject == '')  $subject = "Contact Form Submission"; 


   // Set Message
   $message .= "Email from: " . $name . "<br />";
    $message .= "Email address: " . $email . "<br />";
   $message .= "Message: <br />";
   $message .= $contact_message;
   $message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";

   // Set From: header
   $from =  $name . " <" . $email . ">";

   // Email Headers
    $headers = "From: " . $from . "\r\n";
    $headers .= "Reply-To: ". $email . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


   if (!$error) 

      ini_set("sendmail_from", $siteOwnersEmail); // for windows server
      $mail = mail($siteOwnersEmail, $subject, $message, $headers);

        if ($mail)  echo "OK"; 
        else  echo "Something went wrong. Please try again."; 
        
     # end if - no validation error

    else 

        $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
        $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
        $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
        
        echo $response;

     # end if - there was a validation error



?>

【问题讨论】:

这能回答你的问题吗? PHP mail function doesn't complete sending of e-mail mail() 函数仅根据它是否成功将其传递给 SMTP 服务器返回 true 或 false。您应该检查您的邮件日志或 smtp 服务器日志,了解有关其未发送原因的任何信息。 如果我使用的是虚拟主机,我该如何记录错误? 【参考方案1】:

mail() 功能在 byethost 免费托管中不可用,您需要升级到高级版。

【讨论】:

正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。

以上是关于电子邮件未从 Byethost 主机发送的主要内容,如果未能解决你的问题,请参考以下文章

电子邮件发送本地主机

使用 gmail 从本地主机发送电子邮件

iOS KeyChain 未从后台检索值

从本地主机发送电子邮件

在共享主机上使用 Sendgrid 发送电子邮件

如何正确地从本地主机发送电子邮件 [关闭]