繁体   English   中英

PHP电子邮件未发送

[英]PHP emails not sending

一直在尝试使其工作并从网站发送到我的电子邮件,但这些电子邮件没有通过。

这可能真的很容易。 我也阻止了我实际发送的电子邮件(针对这两个区域)

谢谢你的帮助!

我在index.php中的php代码

<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
$mail_to = 'coverupemail@email.com';
$subject = 'Message from a portfolio visitor '.$field_name;

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

$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$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.');
        window.location = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email manually to coverupemail@email.com');
        window.location = 'index.html';
    </script>
<?php
}
?>

我的HTML代码链接到index.php

<form method="post" action="index.php">
    <p class="contact">
        <input type="text" name="name" id="name" value="" size="22" />
        <label for="name"><small>Name (required)</small></label>
    </p>
    <p class="contact">
         <input type="email" name="email" id="email" value="" size="22" />
         <label for="email"><small>Mail (required)</small></label>
    </p>
    <p class="contact">
        <textarea name="message" id="message" value="" rows="10"></textarea>
        <label for="message"><small>Message (required)</small></label>
    </p>
    <p class="contact">
        <input id="submit" name="submit" type="submit" value="Submit" />
        <input name="reset" type="reset" id="reset" tabindex="5" value="Reset Form" />
    </p>
</form>

$ mail_status的值是多少? 即使其值为“ 1”,它也不能保证发送邮件:(然后,它取决于服务器PHP在消息被传递到服务器的邮件发送部分时返回1。

情况1:如果脚本在服务器上运行,则尝试使用示例代码来验证是否已实际发送邮件,使用以下代码创建页面mailtest.php。

<?php mail("coverupemail@email.com","Test Msg","Hello this is just test message");?>

这将验证是的。

情况2:如果您在本地主机上工作,那么您将必须具有一些SMTP服务器或邮件服务器才能轻松使用gmail通过本地主机发送(我这样做是因为我使用了我的gmail帐户)

另请参阅此链接电子邮件发送

顺便说一句 我认为不使用ini_set()。 b。 还有window.location = 'index.html'; 如果该人向后导航,将只导航到索引页面吗? 邮件会再次发送,也许...所以我建议使用

location.replace('index.html');

谢谢

暂无
暂无

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

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