PHP邮件不会发送到交换或谷歌应用程序帐户

时间:2014-08-29 13:53:55

标签: php email html-email contact-form

我正在尝试使用php mail()函数诊断电子邮件问题。该表单托管在1和1专用服务器上,其中包含site1.com(脚本托管的站点和站点2(我们的站点).site1.com使用交换服务器管理它的电子邮件和我们的站点(site2.com) )使用Google Apps。

邮件表单不会发送到site1.com或site2.com,但它会发送到我的个人Gmail帐户,不会发送到site1.com或site2.com。有没有人有任何想法?

这是邮件代码:

if(isset($_POST["submit_contact"]))
{
// Set submitted variable
$submitted = TRUE;

// Get data and add to variables

$m_name = mysql_real_escape_string($_POST["name"]);
$m_email = mysql_real_escape_string($_POST["email"]);
$m_company = mysql_real_escape_string($_POST["company"]);
$m_phone = mysql_real_escape_string($_POST["phone"]);
$m_enquiry = mysql_real_escape_string($_POST["enquiry"]);
$dateadded = gmdate("Y-m-d H:i:s");
$ip = $_SERVER['REMOTE_ADDR'];
$type = "Website Submission";


    /// Set error messages ///

    $emailError = "Sorry this e-mail is not valid, please try again.";

    ///////////SECURITY CHECKS///////////////////

    /// Check E-mail Authenticity ///
    if(!preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $m_email)) {
        $message = $emailError;
        $error = TRUE;
    }

    // Set email message //
    $errorMessage = "Sorry, you cannot add URLS in this contact form";
    /// Check for urls ///
    if(preg_match("/http/i", "$m_name")) { $message = $errorMessage; $error = TRUE; }
    if(preg_match("/http/i", "$m_email")) { $message = $errorMessage; $error = TRUE; }
    if(preg_match("/http/i", "$m_company")) { $message = $errorMessage; $error = TRUE; }
    if(preg_match("/http/i", "$m_phone")) { $message = $errorMessage; $error = TRUE; }
    if(preg_match("/http/i", "$m_enquiry")) { $message = $errorMessage; $error = TRUE; }

    //// END SECURITY CHECKS ////

    if(!$error) {

        /// Send E-Mail ///
        $em_to = "enquiries@site1.com,me@site2.com,me@gmail.com";
        $em_subject = "Website Contact Form Submission";
        $em_message = "
        <strong>Name:</strong> $m_name<br />
        <strong>Email:</strong> $m_email<br />
        <strong>Phone:</strong> $m_phone<br />";

        if(isset($_POST["callSub"])) 
        {
            $em_message .= "<strong>Time to call:</strong> $m_enquiry<br />";
        } else {
            $em_message .= "<strong>Company:</strong> $m_company<br />
                            <strong>Message:</strong> $m_enquiry<br />";
        }

        $em_message .= "<br /><br />

        <strong>Date Submitted:</strong> $dateadded<br />
        <strong>IP Address:</strong> $ip<br />";

        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: "site1" <'.$m_email.'>\r\n';

        if(mail($em_to, $em_subject, $em_message, $headers)) {
            $error = FALSE;
            $message = "<h3>Thank you for your enquiry, we'll be in touch soon!</h3>";
        } else {
            $error = TRUE;
            $message = "Sorry there was an error processing the form. Please go back and try again.";
        }

1 个答案:

答案 0 :(得分:0)

它在内部发送邮件。我找到how to turn this off on my server并解决了这个问题。