Need help with PHP code.

Asked By 0 points N/A Posted on -
qa-featured

I want to send some emails automatically to yahoo, gmail, hotmail and other websites by using PHP.How can I do this? I 

have tried several methods but still I cannot figure out that why I am not able to send the emails automatically.

SHARE
Answered By 0 points N/A #117805

Need help with PHP code.

qa-featured

 

PHP Simple E-Mail
 
One simplest way to send mails via PHP is to send a text email.
 
– Use a simple function called mail() (Hi!). The syntax for the mail function is
 
mail(string to, string subject, string message, string additional_headers);
 
– Example, I want to send an email to [email protected]
mail("[email protected]", "Test Mail (This is the subject of the E-Mail)", "Type text here");
 
First parameter shows the function of sending email to recipient.
Second parameter is the subject.
Third is the body/content of the email.
 
How to know if your email was sent or if an error occurred.
 
if(mail("[email protected]", "Test E-Mail (This is the subject of the E-Mail)", "This is the body of the Email")){
echo "The email was successfully sent.";
} else {
echo "The email was NOT sent.";
}
 
 
Here is an example of a fully functional script.
 
<?php
$email_to = "[email protected]";
$email_subject = "Test E-Mail (This is the subject of the E-Mail)";
$email_body = "This is the body of the Email nThis is a second line in the body!";
if(mail($email_to, $email_subject, $email_body)){
    echo "The email($email_subject) was successfully sent.";
} else {
    echo "The email($email_subject) was NOT sent.";
}
?>
 

Login/Register to Answer

Related Questions