简体   繁体   English

使用 bluehost 和 outlook 时 PHPmailer 出错

[英]Getting an error with PHPmailer while using bluehost and outlook

Here's my php:这是我的 php:

<?php
    error_reporting(-1);
    ini_set('display_errors', 'On');
    set_error_handler("var_dump");
    $email = $_POST['email'];
    require 'Exception.php';
    require 'PHPMailer.php';
    require 'SMTP.php';
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    $mail = new PHPMailer(true);       
    try {
        //Server settings
        $mail->CharSet="UTF-8";
        $mail->SMTPDebug = 2;             
        $mail->isSMTP();                  
        $mail->Host = 'smtp.office365.com';  
        $mail->SMTPAuth = true;          
        $mail->Username = 'me@vrifyhealth.com';   
        $mail->Password = 'password';        
        $mail->SMTPSecure = 'tls';                 
        $mail->Port = 587;    
        
        $mail->From = "subscriber@vrifyhealth.com";
        $mail->FromName = "Vrify Health Subscriber";
    
        $mail->addAddress("me@vrifyhealth.com", "me");
        $mail->addAddress("other@gmail.com");
    
        //Content
        $mail->isHTML(true);            
        $mail->Subject = 'New subscriber';
        $mail->Body    = 'New email subscriber for Vrify Health: $email</b>';
    
        if($mail->send()){
            header('Location: thank-you.html'); // redirect to 'thank you' page
        }
    } catch (Exception $e) {
        echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
    }
?>

Here's my html:这是我的 html:

<form action="mail.php" method="POST">
              <div class="email-box">
                <input class="tbox" id="email_box" name="email" type="email" style="cursor: pointer;" placeholder="Enter your email">
                <button class="btn" id="email_btn" type="submit" name="button">Subscribe</button>
              </div>
            </form>
            <script language="JavaScript">
              var frmvalidator  = new Validator("contactform");
              frmvalidator.addValidation("email","req","Please provide your email");
              frmvalidator.addValidation("email","email",
                "Please enter a valid email address");
              </script>
              
            <script src="//cdnjs.cloudflare.com/ajax/libs/validate.js/0.13.1/validate.min.js"></script>
            <script>
                const constraints = {
                    name: {
                        presence: {allowEmpty: false}
                    },
                    email: {
                        presence: {allowEmpty: false},
                        email: true
                    },
                    message: {
                        presence: {allowEmpty: false}
                    }
                };

                const form = document.getElementById('contact-form');

                form.addEventListener('submit', function (event) {
                    const formValues = {
                        name: form.elements.name.value,
                        email: form.elements.email.value,
                        message: form.elements.message.value
                    };

                    const errors = validate(formValues, constraints);

                    if (errors) {
                        event.preventDefault();
                        const errorMessage = Object
                            .values(errors)
                            .map(function (fieldValues) {
                                return fieldValues.join(', ')
                            })
                            .join("\n");

                        alert(errorMessage);
                    }
                }, false);
            </script>

I am having an issue having the email sent to my outlook account.我在将 email 发送到我的 outlook 帐户时遇到问题。 I either get it to redirect to the appropriate page, or I get new webpage with a bunch of errors.我要么让它重定向到适当的页面,要么我得到带有一堆错误的新网页。 I'm just trying to have the form send me an email with the new subscriber...what's going on?我只是想让表格向我发送一个带有新订户的 email ......这是怎么回事? Here's the error page:这是错误页面:

错误输出

I realized that with outlook/office 365, $mail->From == $mail->Username我意识到使用 Outlook/Office 365,$mail->From == $mail->Username

I have yet to figure out how to make the from address tailored to what I want it to say.我还没有弄清楚如何使发件人地址适合我想要表达的内容。

Also SSL works and in order to get a proper redirect you need to set $mail->SMTPDebug to 0 SSL 也可以工作,为了获得正确的重定向,您需要将 $mail->SMTPDebug 设置为 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM