从@yahoo帐户以外的所有发件人处接收的PHP联系人表格

时间:2018-07-03 14:55:50

标签: php apache

我已经创建了一个php联系人表单,并且在大多数情况下,除了发件人使用@yahoo电子邮件地址之外,它似乎都可以正常工作。我已经使用hotmail和gmail地址进行了测试,并且一切都正常。

我使用PHPMailer来尝试避免此类问题,但它似乎仍然无法正常工作。

任何帮助都是很好的,如果您可以提供很棒的示例代码!

作为旁注-我正在通过godaddy托管index.php文件(不确定是否会引起问题)

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

$msg = "";

if (isset($_POST['submit'])) {
    require 'phpmailer/src/Exception.php';
    require 'phpmailer/src/PHPMailer.php';
    require 'phpmailer/src/SMTP.php';

    function sendemail ($to, $from, $body) {
        $mail = new PHPMailer(true);
        $mail->setFrom($from);
        $mail->addAddress($to);
        $mail->Subject = 'Contact Form - Email';
        $mail->Body = $body;
        $mail->IsHTML(false);

        return $mail->send();
    }

    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $body = $_POST['body'];

    if (sendemail('example@gmail.com', $email, $subject, $body)) {
        $msg = 'Email has been sent, thank you!';
    } else 
        $msg = 'Email failed, please try again later';       

    }

?>

<title>Test Contact Form Using PHPMailer</title>

<body>

    <div id="contactInnerWrapper">
        <a href="#"><span id="close">&times;</span></a>
        <h1 id="h1contactForm">Get in touch</h1>
            <form method="post" action="index.php">
                <label for="email">Email address:</label><br>
                <input  type="email" name="email"  placeholder="Enter email" id="email">
                <label for="subject">Subject:</label>
                <input  type="text" name="subject" id="subject"><br>
                <label for="body">What would you like to ask us?</label><br>
                <textarea  type="text" name="body" rows="7" id="content"></textarea>
                <button type="submit" name="submit" id="submit">Submit</button>
            </form>
            <br><br>
            <?php echo $msg; ?>
    </div>


</body>

0 个答案:

没有答案