【发布时间】:2012-03-17 01:27:13
【问题描述】:
我想通过 php 使用 xampp 发送电子邮件。
<html>
<head>
</head>
<body>
<?php
error_reporting(E_ALL ^ E_NOTICE);
$to = $_POST['email_add'];
//define the subject of the email
$subject = $_POST['sbjct'];
//define the message to be sent. Each line should be separated with \n
$message = $_POST['msg'];
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
<form action="send_email.php" method="post">
Email Add<input type="text" name="email_add" />
Subject<input type="text" name="sbjct" /> <br>
<textarea name="msg" rows="9" cols="20"></textarea><br>
<input type="submit" value="Send"/>
</form>
</body>
</html>
它不工作。我的代码有问题吗?
在云上找了一些教程,但是里面提到了SMTP,我没看懂。
【问题讨论】:
-
将
error_reporting(E_ALL ^ E_NOTICE);更改为error_reporting(E_ALL);并从@mail()中删除@。您可能需要设置经过身份验证的 SMTP。 -
你可以在xammp中使用mercury邮件服务器。