Mail/mime 使用 jquery 显示表单时未发送电子邮件

Mail/mime email not sent when displaying form with jquery

我有一个相对基本的电子邮件表单,我打算使用邮件 mime 通过电子邮件将其发送给收件人。过去,当表单显示在自己的页面(即联系页面)上时,这种方法对我有用。

我在这里使用 jquery 来显示一个隐藏的 div,其中包含我在主页上的表单。问题是虽然我的验证通过了,但电子邮件没有被发送。我不知道为什么,希望这里有人能帮助我!

相关php如下:

$path = get_include_path() . PATH_SEPARATOR . '/home/host/php';
set_include_path($path);
include('Mail.php');
include('Mail/mime.php');
$recipient_email = 'somebody@somewhere.com';
//validations are here

//send the email
$name = $_POST['name'];
$visitor_email = $_POST['from'];
$subject = $_POST['subject'];
$user_message = $_POST['message'];
$to = $recipient_email;
$from = $visitor_email;
$text = "From: $name \n Subject: $subject \n Message $user_message";

$message = new Mail_mime(); 
$message->setTXTBody($text); 
$body = $message->get();
$extraheaders = array("From"=>$name, "To"=>$recipient_email, "Subject"=>$subject, "Reply-To"=>$visitor_email);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
echo "Success";

显示表单的 jquery 如下所示:

jQuery.fn.fadeToggle = function(speed, easing, callback) {
return this.animate({opacity: 'toggle'}, speed, easing, callback);  
};

$(document).ready(function() {
$('#tellfriend').hide();
$('li a.email, #tellfriend a.close').click(function() {
$("#tellfriend").fadeToggle('slow');
});
}); 

我的一个想法(我会用它来试验)是因为当单击 link 以显示表单时,link 附加到 URL 并且所以它可能会影响我的表单操作?不确定.. 任何帮助表示赞赏!

我能够按照我最终在 Stack Overflow 上找到的上一个问题解决我的问题 HERE

事实证明,我必须指定一个外发邮件服务器才能发送表单。不过,奇怪的是,我过去曾在不需要遵循这些步骤的情况下使用它。