How to send email without smtp in PHP?

by tressie.damore , in category: PHP General , 2 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 = "[email protected]";
$subject = "Test email using PHP mail function";
$message = "This is a test message.";
$headers = "From: [email protected]";

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 "[email protected]" 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 "[email protected]".


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 , a year 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.