【问题标题】:php cant send emailphp无法发送邮件
【发布时间】:2014-02-09 09:31:11
【问题描述】:

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

但如果我按确定,我将无法向 **@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>

请帮帮我

【问题讨论】:

标签: php sendmail


【解决方案1】:

最好使用专用脚本发送电子邮件。例如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

【讨论】:

  • 如何获取 smtp 的用户名和密码
  • 这是来自您的服务器。如果您从 SMTP 服务器发送电子邮件,那么这些将是该电子邮件帐户的用户名和密码。您也可以选择不使用 SMTP。查看 PHPMailer 示例,看看哪个最适合您 - phpmailer.worxware.com/index.php?pg=examples
猜你喜欢
  • 2013-09-04
  • 2013-01-24
  • 2012-08-31
  • 2014-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-25
  • 1970-01-01
相关资源
最近更新 更多