The example in this article describes the method of using PHP to send various types of emails using the SAE native Mail class. I share it with you for your reference. The details are as follows:
Everyone who has used SAE knows that among all SAE services, the Mail service is the worst. From time to time, emails cannot be sent. Especially corporate post offices, even Sina's own corporate post office has problems. Solutions today.
First, let’s take a look at the DEMO given in the SAE document:
$mail = new SaeMail(); $mail->setAttach( array( 'my_photo' => '照片的二进制数据' ) );//附件发送方法 $ret = $mail->quickSend( 'to@sina.cn' , '邮件标题' , '邮件内容' , 'smtpaccount@unknown.com' , 'password' , 'smtp.unknown.com' , 25 ); // 指定smtp和端口
The DEMO given by SAE uses the quicksend() method. This method has been tested by me and it works when using non-enterprise post offices. Sent perfectly and has a high delivery rate. But please note that you can only use SMTP port 25 and cannot use SSL connection. I don’t know if the opening method is wrong. I hope someone can give me some advice.
But for a website, it is very important to have its own independent domain name mailbox. This is where the corporate post office comes in handy. Just using the quicksend() method always fails to send. So we have to use the send() method. The send() method is slightly more complicated to use:
1. First set the send parameter setOpt(). The set send parameter is invalid for the quicksend() method and is only valid for send().
$mail = new SaeMail(); $mail->setOpt(array( 'from' => '发件邮箱', 'to' => trim($to),//接收信箱 'smtp_host' => 'smtp服务器' , 'smtp_port' => 25, //port 'smtp_username' => '账户全名', 'smtp_password' => '密码', 'subject' => '主题', 'content' => '内容', 'content_type' => 'HTML' //发送格式,默认是text ) ); $ret = $mail->send();
That’s it, that’s it. You can check more parameters in the official documentation.
Since this site only provides email prompts for comment replies, there is no SSL test in send(). You can test it yourself if necessary.
That’s it. If you don’t like this method, you can also use Baidu’s third-party Mail class library, which is also possible. After testing, sending and receiving letters takes about 3 seconds, which can meet most needs.
I hope this article will be helpful to everyone in PHP programming.
For more articles on how PHP uses the SAE native Mail class to send various types of emails, please pay attention to the PHP Chinese website!