Home > Backend Development > PHP Tutorial > Solution to the problem of sending emails in php

Solution to the problem of sending emails in php

墨辰丷
Release: 2023-03-31 09:30:01
Original
1949 people have browsed it

This article mainly introduces the solution to the problem of sending emails in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.

php is used to send emails. The open source project PHPMailer is generally used to implement it. So besides this, are there any other good projects?

Solution:

Use SMTP protocol to send emails

Use its built-in email class in CodeIgniter to send emails

$this->load->library('email');

$to = "aa@bb.cc";
$subject = "test";
$message = "hello!";

$config["protocol"]   = "smtp";
$config["smtp_host"]  = "smtp.163.com";
$config["smtp_user"]  = "username@163.com";
$config["smtp_pass"]  = "password";
$config["mailtype"]   = "html";
$config["validate"]   = true;
$config["priority"]   = 3;
$config["crlf"]     = "/r/n";
$config["smtp_port"]  = 25;
$config["charset"]   = "utf-8";
$config["wordwrap"]   = TRUE;
$this->email->initialize($config);
$this->email->from('xxxx@163.com', 'xxxx');
$this->email->to($to);   
$this->email->subject($subject);
$this->email->message($message); 
$this->email->send();
Copy after login

Send in this way There is no need to install any software for email, but it does require you to write more code and be familiar with SMTP.

But if you don’t write it yourself, but directly use the ready-made code written by others, then this method is undoubtedly the most trouble-free:

There is no need to build an SMTP server yourself, and No need to write a lot of code.

Summary:

Currently, PHP comes with the mail() function based on sendmail to send emails, but the premise is that sendmail must be installed on the server. Many servers The space provider does not have a sendmail mail server installed. So there are certain limitations.

So there are currently many open source components for sending emails based on SMTP. The most famous one is probably phpMailer. You already know this and I won’t go into details. I’ll talk about other methods here.
1. OK

2. JMail: JMail is a component under Windows, but PHP supports calling it through COM. This is also a solution, but the premise is that the Web Server can be considered if it runs on Windows, otherwise it is still considered Come on.

3. There are many mail classes based on SMTP written by many people on the Internet, which are also usable, but the supported functions are relatively simple. If the requirements are not high, you can also consider it.

4. Here are 20 more well-known open source PHP components for sending emails. I have not tested them one by one, so I have no opinion. You can try it yourself. Paste the address here:
Introducing 20 PHP mail open source projects

Summary:The above is the entire content of this article, I hope it will be helpful to everyone's learning .

Related recommendations:

PHP Mysql jQuery implements password retrieval function

php uses regular expressions Extract links in content

PHP form data validation class

The above is the detailed content of Solution to the problem of sending emails in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template