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

Solution to the problem of sending emails in php

Jun 09, 2018 pm 02:11 PM
php send email

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles