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.
Need help with PHP code.
Â
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);
Â
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_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.";
}
?>
Â