有人可以用phpmailer帮助我吗? [英] Can someone help me out with phpmailer?
问题描述
我已经发送了HTML电子邮件,到目前为止一切正常.我打算用PHP发送它(使用mail();函数).但是,当我这样做时,邮件没有到达hotmail和gmail帐户.我在Google上搜索了一下,有人建议使用PHPmailer.
I've made a HTML email and everything has worked so far. I was planning to send it with PHP (using the mail(); function). However, when I did this, the mail did not arrive at hotmail and gmail accounts. I googled around a bit and people suggested to use PHPmailer.
我下载了PHPmailer并将其安装在服务器上.到目前为止,一切都很好.但是现在我有以下代码:
I downloaded PHPmailer and installed it on my server. So far, so good. But now I have the following code:
<?php
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\phpmailer.inc.php');
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\smtp.inc.php');
require("phpmailer.inc.php");
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->From = "from@example.com";
$mail->AddAddress("mymail@mydomain.com");
$mail->Subject = "An HTML Message";
$mail->Body = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";
if($mail->Send()) {
echo 'Message is sent';
} else {
echo 'Message was not sent..';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>
我遇到了几个问题:
- 输出告诉我电子邮件未发送,但是已经发送.
- 我有两个科目
- 如果我添加更多的html(如表格),它仍然会被hotmail(也可能是gmail)拒绝.
此外,我看到了SMTP功能.如何使用此功能?我需要写下自己的SMTP吗?
Also, I saw there's a SMTP function. How to use this function? Do I need to write down my own SMTP?
如果有人可以帮助我,会很高兴!
Would be very happy if someone could help me out!
class SMTP {
var $SMTP_PORT = 25; # the default SMTP PORT
var $CRLF = "\r\n"; # CRLF pair
var $smtp_conn; # the socket to the server
var $error; # error if any on the last call
var $helo_rply; # the reply the server sent to us for HELO
var $do_debug; # the level of debug to perform
/*
* SMTP()
*
* Initialize the class so that the data is in a known state.
*/
function SMTP() {
$this->smtp_conn = 0;
$this->error = null;
$this->helo_rply = null;
$this->do_debug = 0;
}
推荐答案
我在不同的项目中使用PHPMailer.
I use PHPMailer in different projects.
我建议您通过SMTP发送邮件,当然PHPMailer支持它:
I suggest you to send the mails via SMTP, of course PHPMailer supports it:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.gmail.com" //(or the smtp server you use)
$mail->Port = "465" //(gmail uses secure smtp so that runs on port 465)
$mail->SMTPAuth = "true" //we need to autenticate to the server
$mail->SMTPSecure = "ssl" //we use ssl to protected the flow of info
$mail->Username = "mymail@gmail.com" //account
$mail->Password = "password" //password
//build the message
$mail->IsHTML(true);
$mail->From = "mymail@gmail.com";
$mail->AddAddress("mymail@mydomain.com"); //who receives the mail
$mail->Subject = "An HTML Message";
$mail->Body = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";
if($mail->Send()) {
echo 'Message is sent';
}
else {
echo 'Message was not sent..';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
这篇关于有人可以用phpmailer帮助我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!