我有以下php代码:
<?
if ($_POST['emailme']) {
$yemail = $_POST['email'];
$host = $_SERVER['HTTP_HOST'];
$email = "<autoreply@$host>";
if (mail('$yemail', 'This is a Subject', 'This is the body of the email', 'From: $email')) {
echo "Message sent!";
} else {
echo "Message failed sending!";
}
}
?>
这是我的HTML:
<FORM METHOD="POST" ACTION=""><INPUT TYPE='TEXT' CLASS='BOX' NAME='email' /><INPUT TYPE='SUBMIT' NAME='emailme' CLASS='SUBMITBOX' VALUE='Send!' /></FORM>
为什么不发送电子邮件的任何想法?它说消息已发送,但我没有在我的收件箱中收到任何电子邮件
非常感谢所有帮助,谢谢
PS:我尝试了以下(双引号):
if (mail("$yemail", "This is a Subject", "This is the body of the email", "From:" . $email)) {
echo "Message sent!";
} else {
echo "Message failed sending!";
}
但仍然没有运气
答案 0 :(得分:4)
试试这个
if (mail('akh40@hotmail.co.uk', 'This is a Subject', 'This is the body of the email', 'From:'. $email))
答案 1 :(得分:2)
显然,大多数托管公司都放弃了对php的mail()功能的支持,转而使用SMTP版本的电子邮件脚本。
有关原因的解释,请参阅http://www.thesitewizard.com/php/protect-script-from-email-injection.shtml。
尝试使用SMTP / SSL脚本:
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://mail.example.com";
$port = "465";
$username = "smtp_username";
$password = "smtp_password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>