如何在PHP中发送邮件?

时间:2013-07-06 11:44:20

标签: php html windows phpmyadmin

任何人都可以通过php发送带有附加对象的邮件的方式.plz我是新手,在这方面帮助我。是否有任何服务器要安装?邮件应该在任何电子邮件帐户上,以及PLZ帮助我在这里。任何人提供我教程的链接我使用教程HERE它显示错误Fatal error: Call to undefined function IsSMTP() in C:\wamp\www\EMS3\mail.php on line 13 PLZ帮助我在这

3 个答案:

答案 0 :(得分:1)

此处提供的示例中存在错误。使用以下代码。

require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username@doamin.com"; //Reply to this email ID
$email="username@domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

更新您还需要设置您使用的外部SMTP服务器。如果你使用谷歌。我相信它的smtp.gmail.com

  $mail->Host = "smtp.gmail.com";
  $mail->Port = 465;
  $mail->Secure = "ssl";

答案 1 :(得分:0)

您可以使用外部PHP库发送邮件,我已在内部使用本地主机,但仍配置参数以发送到外部源。该套餐为Swift Mailer

答案 2 :(得分:-3)

在localhost中,您无法发送任何邮件。托管后,这是可能的。