我有以下代码可以正确发送电子邮件,但收到的电子邮件的 FROM 值为 root@mysite.com 。我希望收到的电子邮件 FROM 的值是价值电子邮件(在联系表格中输入),以便可以轻松地回复收到的电子邮件。任何援助将不胜感激。谢谢
<?php
if ($_POST["email"]<>'')
{
require_once "Mail.php";
$from = "root@mysite.com";
$to = "info <info@mysite.com>";
$subject = "Contact us info from Website";
$body = "Name: ".$_POST["name"]."\r\n";
$body .= "Email: ".$_POST["email"]."\r\n";
$body .= "Phone: ".$_POST["phone"]."\r\n";
$body .= "Comment: ".nl2br($_POST["comment"])."";
$host = "mail.mysite.com";
$username = "root@mysite.com";
$password = "abcdefghijk";
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body, "FROM: $email","-f$replyToEmail");
mail("$toEmail", $subject, $message, "FROM: $fromEmail","-f$replyToEmail");
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>