php无法发送电子邮件

时间:2014-02-09 09:31:12

标签: php sendmail

我有将电子邮件发送到我的电子邮件的代码

但如果按下确定我就无法发送电子邮件至 * * @ hotmail.com

我在linux服务器(fedora)上工作,我不会改变任何设置

我的mail.html文件是

<html>
<head><title>Mail sender</title></head>
<body>
<form action="mail.php" method="POST">
<b>Email</b><br>
<input type="text" name="email" size=40>
<p><b>Subject</b><br>
<input type="text" name="subject" size=40>
<p><b>Message</b><br>
<textarea cols=40 rows=10 name="message"></textarea>
<p><input type="submit" value=" Send ">
</form>
</body>
</html>

我的email.php文件是:

<html>
<head><title>PHP Mail Sender</title></head>
<body>
<?php

# Retrieve the form data
$email      = $_POST['email'];
$subject    = $_POST['subject'];
$message = $_POST['message'];

# Sends mail and report success or failure
if (mail($email,$subject,$message)) {
  echo "<h4>Thank you for sending email</h4>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?>
</body>
</html>

请尝试帮帮我

1 个答案:

答案 0 :(得分:0)

最好使用专用脚本发送电子邮件。例如PHPMailer为您提供各种配置选项,包括SMTP:

// Send Mail
$mail = new PHPMailer(); // initiate
$mail->IsSMTP(); // use SMTP

// SMTP Configuration
$mail->SMTPAuth = true; // set SMTP
$mail->Host = "myhost"; // SMTP server
$mail->Username = "email@email.com";
$mail->Password = "password";            
$mail->Port = 465; // change port is required