我收到了一份联系表格,成功地向我发送了电子邮件。
继承人提取物:
$_POST['message'] = wordwrap($_POST['message'], 70);
mail ('myemail@test.com', $_POST['subject'], $_POST['message'] , $_POST['email']);
echo "<div class='registertext'>Your email was succesfully sent to a member of the administration team. Please wait 24 hours for as to reply and ensure you check your junk mail!<br />To login please click <a href='login.php'>here</a></div>";
我遇到的问题是,电子邮件是从我的主机发送的。不是我想要指定的电子邮件。我怎么克服这个?
答案 0 :(得分:0)
您可以在电子邮件标题中指定它:
$recipient = "recipient@test.com";
$from = "You@yoursite.com";
$replyTo = "You@yoursite.com";
$subject = "Hi!";
$text = "<p>This is a test!<p>";
$headers = "MIME-Version: 1.0\r\n"
."Content-Type: text/html; charset=utf-8\r\n"
."Content-Transfer-Encoding: 8bit\r\n"
."From: =?UTF-8?B?". base64_encode([Your Name]) ."?= <$from>\r\n"
."Reply-To: $replyTo\r\n"
."X-Mailer: PHP/". phpversion();
//send it!
if (mail($recipients, $subject, $text, $headers, "-f $from")){
echo "sent";
} else {
echo "did not send";
};
但很有可能会被SPAM过滤器捕获。在这种情况下,您最好的选择是使用PHP邮件库来处理SMTP电子邮件并使用您的实际帐户发送邮件(有几个软件包可以为您处理此问题:Pear Mail和PHP Mailer等等。
答案 1 :(得分:0)
您可以使用将使用SMTP帐户的PEAR邮件。以下是我使用的邮件表单中的一些代码
$from = "Name <webmaster@domain.com>";
$to = "Name <address@domain.com>";
$subject = "Subject";
$body = 'A message!';
$host = "ssl://domain.com";
$port = "465";
$username = "username";
$password = "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>");
}