我正在设计一个紧急响应页面,我们需要的一个功能就是能够点击一个按钮(例如“发送详细信息到大使馆”),然后将自动生成的电子邮件发送给目标收件人($email_address)必须进入Microsoft Outlook并单击“发送”.有没有办法做到这一点?
我知道的唯一方法是< a href ='mailto:example@test.com'\u0026gt;一,但这会打开Outlook中的电子邮件,我真的需要它完全自动化.
像这样的东西可以作为一个起点:
<form action="" method="post">
<input type="submit" value="Send details to embassy" />
<input type="hidden" name="button_pressed" value="1" />
</form>
<?PHP
if(isset($_POST['button_pressed']))
{
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . PHPversion();
mail($to,$subject,$message,$headers);
echo 'Email Sent.';
}
?>
UPDATE
这可以用作Javascript函数来调用mail.PHP页面并发送电子邮件而无需重新加载页面.
function sendemail()
{
var url = '/mail.PHP';
new Ajax.Request(url,{
onComplete:function(transport)
{
var Feedback = transport.responseText.evalJSON();
if(Feedback.result==0)
alert('There was a problem sending the email,please try again.');
}
});
}
你需要Prototype这个方法:http://www.prototypejs.org/api/ajax/request
我没有测试过这个,但希望它应该是正确的.