PHP uses SMTP to send emails (PEAR)
Release: 2016-07-25 09:09:15
Original
869 people have browsed it
Most PHPer uses the mail function to send emails, but we can use other SMTP servers to send emails. It is recommended here
PEAR’s mail package to send emails.
- $subject = "This mail is sent from SMTP.";
- $mail_body = "This is the body of the mail which is sent using SMTP.";
- $from = "From: From Name ";
- $to = "To: To Name ";
- $receiver = "toaddress@xpertdeveloper.com";
-
- // Setting up the headers
- $headers[" From"] = $from;
- $headers["To"] = $to;
- $headers["Subject"] = $subject;
- $headers["Reply-To"] = "reply@address.com";
- $headers["Content-Type"] = "text/plain; charset=ISO-2022-JP";
- $headers["Return-path"] = "returnpath@address.com";
-
- // Setting up the SMTP setting
- $smtp_info["host"] = "smtp.server.com";
- $smtp_info["port"] = "25";
- $smtp_info["auth"] = true;
- $smtp_info["username "] = "smtp_user";
- $smtp_info["password"] = "smtp_password";
-
- // Creating the PEAR mail object :
- $mail_obj =& Mail::factory("smtp", $smtp_info);
-
- // Sending the mail now
- $mail_sent = $mail_obj->send($receiver, $headers, $mail_body);
-
- // If any error the see for that here:
- if (PEAR::isError($mail_sent )) { print($mail_sent->getMessage());}
Copy code
|
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31