【问题标题】:contact_us.php isn't sending emails to my website associated mail addresscontact_us.php 没有向我的网站关联邮件地址发送电子邮件
【发布时间】:2019-01-18 18:15:20
【问题描述】:

我正在使用这个contact_us.php 文件来启用我网站的“联系我们”部分。如果我在这里使用我的 gmail 或 hotmail 地址 $mail_to = 'user@gmail.com';它完美地工作。但是,如果我使用与网站关联的电子邮件地址,我的意思是 $mail_to = 'user@mywebsite.com';我没有收到任何邮件到我的收件箱。我什至检查了我的垃圾邮件和所有其他文件夹。谁能帮我解决这个问题?如何将电子邮件发送到与我的网站关联的电子邮件地址。提前致谢。

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'user@mywebsite.com';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to user@yahoo.com');
        window.location = 'index.html';
    </script>
<?php
}
?>

【问题讨论】:

标签: php html


【解决方案1】:

如果你不想使用邮件功能,可以试试 PHPmailer 库中的 SMTP 邮件。

您将能够从您的 gmail 或 Outlook 或您网站上的任何其他 smtp 帐户发送电子邮件。分享以下链接:

https://github.com/PHPMailer/PHPMailer/tree/master/examples

享受:)

【讨论】:

    猜你喜欢
    • 2014-07-20
    • 2012-06-24
    • 2017-03-01
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多