How to send email without smtp in PHP?

by tressie.damore , in category: PHP General , 3 years ago

How to send email without smtp in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by jasen_gottlieb , 2 years ago

@tressie.damore 

To send an email without using SMTP in PHP, you can use the mail function.


Here is a simple example of how to use the mail function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php
$to = "recipient@example.com";
$subject = "Test email using PHP mail function";
$message = "This is a test message.";
$headers = "From: sender@example.com";

if (mail($to, $subject, $message, $headers)) {
    echo "Email was sent successfully.";
} else {
    echo "There was an error sending the email.";
}
?>


This example will send an email to "recipient@example.com" with the subject "Test email using PHP mail function" and the message "This is a test message." The email will appear to be sent from "sender@example.com".


Keep in mind that the mail function may not work on all servers, and it may be necessary to use an SMTP server to send emails. Additionally, emails sent using the mail function may be more likely to be flagged as spam by email providers.

Member

by domenico , 2 years ago

@tressie.damore 

It is not possible to send an email without SMTP in PHP as SMTP (Simple Mail Transfer Protocol) is the standard protocol used for sending emails over the Internet. SMTP is required to establish a connection with the mail server and transfer the email message.

Related Threads:

How to send email in Codeigniter without smtp?
How to send email with smtp in php?
How to send email using smtp in php?
How to send an html email using smtp in php?
How to send smtp email in perl?
How to send email in Codeigniter using smtp?