PHP Mailer Office 365

时间:2016-03-17 09:11:36

标签: php html email office365

我刚刚开始进行Web开发,我的任务是创建一个web-mail php表单。我能够在线提取资源,它可以完美地使用gmail,outlook.com和几乎所有其他电子邮件服务,但是当我添加我的Office 365帐户时,我从未收到消息。我从@ a2plcpnl0560.prod.iad2.secureserver.net域收到来自godaddy的电子邮件,但不在我的办公室365电子邮件中。我已经通过论坛,目前我还没有足够的知识知道从哪里开始解决问题。我已经看到了PHPMailer的使用示例,我尝试使代码工作,但在我的域上,我从来没有从表单本身获得确认消息。我不确定在Office 365的管理中心是否需要配置一些内容才能使其正常工作。任何信息都将不胜感激。

<?php

if(isset($_POST['email'])) {
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "info@office365.com";
    $email_subject = "Inquiry";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists

    if(!isset($_POST['first_name']) ||        !isset($_POST['last_name']) ||        !isset($_POST['email']) ||        !isset($_POST['telephone']) ||        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $first_name = $_POST['first_name'];
    // required
    $last_name = $_POST['last_name'];
    // required
    $email_from = $_POST['email'];
    // required
    $telephone = $_POST['telephone'];
    // not required
    $comments = $_POST['comments'];
    // required
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

    if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    }

    $string_exp = "/^[A-Za-z .'-]+$/";

    if(!preg_match($string_exp,$first_name)) {
        $error_message .= 'The First Name you entered does not appear to be valid.<br />';
    }


    if(!preg_match($string_exp,$last_name)) {
        $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
    }


    if(strlen($comments) < 2) {
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
    }


    if(strlen($error_message) > 0) {
        died($error_message);
    }

    $email_message = "Form details below.\n\n";

    function clean_string($string) {
        $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
    // create email headers
    $headers = 'From: '.$email_from."\r\n".'Reply-To: '.$email_from."\r\n" .'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>

您的请求已经提交,有人会尽快与您联系!

0 个答案:

没有答案