开发者

How do I send an email using Javascript?

开发者 https://www.devze.com 2023-01-08 08:45 出处:网络
How do I send email using JavaScript? I 开发者_Go百科don\'t want to use mailto, because if I use mailto it will open an email client.Can\'t be done. Sending e-mail only works on the server side. If a

How do I send email using JavaScript?

I 开发者_Go百科don't want to use mailto, because if I use mailto it will open an email client.


Can't be done. Sending e-mail only works on the server side. If all you're doing is sending e-mail, a quick PHP script would likely do the trick.


I agree with @Matchu. Sending email requires server side languages and Javascript is client side languages. In this case, the best way would be to use PHP. When you'll PHP you've lot's of the option to send an email how you like. Here's the relevant example which you can use to send an email by using the PHP default mail() function.

<?php
$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);
0

精彩评论

暂无评论...
验证码 换一张
取 消