我想在html中使用php发送电子邮件。出于此目的,我写了以下代码:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ( mail ('ahmsjahan@gmail.com','New Website message' ,$_POST['message']))
$status = "Thank you for your message";
}
if ( isset($status))
echo $status;
?>
<html>
<head>
<title>
I am don
</title>
</head>
<body>
<h1>
Contact Form
</h1>
<form action = "" method = "post">
<ul>
<li>
<label for = "name"> Name: </label>
<input type = "text" id="name"name = "name">
</li>
<li>
<label for = "email" > Email: </label>
<input type="email" id="email" name = "email">
</li>
<li>
<label for = "messsage" > Message: </label><br>
<textarea name = "message" id="message"></textarea>
</li>
<li>
<input type = "submit" value= "submit">
</li>
</ul>
</form>
</body>
</html>
我收到这样的错误:
发送时(!)警告:mail():无法连接到“localhost”端口25的邮件服务器,验证php.ini中的“SMTP”和“smtp_port”设置,或者在C:\ wamp中使用ini_set()第4行\ www \ form.php
我应该在php.ini文件的第4行更改某些内容吗?
答案 0 :(得分:0)
打开php.ini文件并搜索[mail function]并添加/更改邮件服务器的详细信息。重新启动您的Web服务器。
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = me@example.com