How to Send Email From a PHP Script
How to Send Email From a PHP Script GA S REGULAR Menu Lifewire Tech for Humans Newsletter! Search Close GO Email, Messaging, & Video Calls > Email
error_reporting( E_ALL );
$to = "youremailrecipient@example.com";
$subject = "Your subject here";
$message = "Your message here";
echo "The email message was sent.";
?> The first two lines allow you to see any errors that may occur with the script: ini_set( 'display_errors', 1 );
error_reporting( E_ALL ); Next is the To line. This is the email address the email should be sent to. This email address could be yours or someone else's, depending on why you're using the PHP mail function. $to = "youremailrecipient@example.com"; In the Subject line, type whatever you want to be used as the subject of the emails sent through this PHP script. $subject = "Your subject here"; The Message line is where the body of the email goes. $message = "Your message here"; Use the \n parameter to add a new line to the message so that it doesn't all display on a single line to the recipient. Add more than one, if you need to. The echo message would be a success or error message that displays on the page if the other parameters aren't properly filled out. echo "The email message was sent."; You can also send email from your PHP script using SMTP authentication, specifying whether the PHP email script should use a local or remote SMTP server for sending messages.
How to Send Email From a PHP Script
Learn how to program a web page to send PHP mail
By Heinz Tschabitscher Heinz Tschabitscher Writer University of Vienna A former freelance contributor who has reviewed hundreds of email programs and services since 1997. lifewire's editorial guidelines Updated on June 15, 2022 Tweet Share Email Tweet Share EmailIn This Article
Expand Jump to a Section PHP Mail Script Example More PHP Email Options Protect Your Script From SpammersWhat to Know
Script: Enter ini_set( 'display_errors', 1 ); error_reporting( E_ALL ); $to = "youremailrecipient@example.com"Next: $subject = "Your subject here"; $message = "Your message here"; echo "The email message was sent."; ?Fill in relevant details (email address, email subject, message, etc.) as needed. This article explains how to send an email from a PHP script running on a webpage by using a Sendmail program to send emails from your web server rather than your mail server.PHP Mail Script Example
If you implement this example, make sure to change the elements that apply to you, such as your email address, subject, and message. ini_set( 'display_errors', 1 );error_reporting( E_ALL );
$to = "youremailrecipient@example.com";
$subject = "Your subject here";
$message = "Your message here";
echo "The email message was sent.";
?> The first two lines allow you to see any errors that may occur with the script: ini_set( 'display_errors', 1 );
error_reporting( E_ALL ); Next is the To line. This is the email address the email should be sent to. This email address could be yours or someone else's, depending on why you're using the PHP mail function. $to = "youremailrecipient@example.com"; In the Subject line, type whatever you want to be used as the subject of the emails sent through this PHP script. $subject = "Your subject here"; The Message line is where the body of the email goes. $message = "Your message here"; Use the \n parameter to add a new line to the message so that it doesn't all display on a single line to the recipient. Add more than one, if you need to. The echo message would be a success or error message that displays on the page if the other parameters aren't properly filled out. echo "The email message was sent."; You can also send email from your PHP script using SMTP authentication, specifying whether the PHP email script should use a local or remote SMTP server for sending messages.