如何在PHP中实现mail()函数? [英] How to implement mail() function in PHP?
问题描述
我是php的初学者。我正在尝试在PHP.Code中实现mail()看起来正确但邮件发送失败。这是我的代码。
< !DOCTYPE html >
< head >
< title > 表单提交 < / title >
< / head >
< body >
< 表格 方法 = post action = < span class =code-keyword> mail.php >
电子邮件:< ; 输入 名称 < span class =code-keyword> = email 类型 = text / > < < /温泉n> br / >
主题:< 输入 < span class =code-attribute> name = subject type = text / > < br / >
消息:< br / >
< < span class =code-leadattribute> textarea name = 评论 行 = 15 cols = 40 > < / textarea > < br / >
< input type = 提交 < span class =code-attribute> value = 提交 / >
< / form >
< / body >
< span class =code-keyword>< / html >
<?php
// 如果填写email变量,发送电子邮件
// 电子邮件信息
$ admin_email = jsathish1989@gmail.com;
$ email = $ _REQUEST [' email 跨度>];
$ subject = $ _REQUEST [' subject 跨度>];
$ comment = $ _REQUEST [' comment 跨度>];
// 发送电子邮件
$ mail = mail($ admin_email, $ subject,$ comment, 发件人:。$ email);
if($ mail){
echo 感谢您使用我们的邮件表格;
} else {
echo 邮件发送失败。;
}
?>
如果我需要对php.ini文件做任何事情,那么我应该在该文件中做些什么呢?
< pre lang =css> [mail function]
; 对于 Win32 仅。
; http: // php.net/smtp
SMTP = localhost
; http: // php.net/smtp-port
smtp_port = 25
; 对于 Win32 仅跨度>。
; http: // php.net/sendmail-from
; sendmail_from = me @ example。 com
; < span class =code-leadattribute>对于 Unix 仅。 您 可能 supply arguments as well (默认值: sendmail - t -i)。
; http: // php.net/sendmail-path
; sendmail_path =
admin_email = jsathish1989@gmail.com;
email =
_REQUEST [' email'];
I am beginner to php.I am trying to implement mail() in PHP.Code looks correct but the mail sending is failed.Here is my code.
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form method="post" action="mail.php">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
<?php
//if "email" variable is filled out, send email
//Email information
$admin_email = "jsathish1989@gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
$mail=mail($admin_email, "$subject", $comment, "From:" . $email);
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
?>
If I need to do anything with php.ini file, then what exactly I should do in that file?
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
admin_email = "jsathish1989@gmail.com";
email =
_REQUEST['email'];
这篇关于如何在PHP中实现mail()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!