![]() |
|
Tutorial and Explanation of How to Send an Email with PHP - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: PHP (https://sinister.ly/Forum-PHP) +--- Thread: Tutorial and Explanation of How to Send an Email with PHP (/Thread-Tutorial-and-Explanation-of-How-to-Send-an-Email-with-PHP) |
Tutorial and Explanation of How to Send an Email with PHP - Woody - 02-15-2012 Below you will find the source to send an email in PHP.
Code: <?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi, How are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>Now, let me explain each line.
The <?php and ?> are kind of like the <html> and </html tags. These are both tags. The <?php is the opening tag, and the ?> is the closing tag. Now, you may be wondering, why is there dollar signs. Well dollar signs show that it is a variable. So $to is a variable and the variable equals recipient@example.com. The $subject is a variable also, and it equals Hi. Finally, the last variable is $body and it equals Hi, how are you. Now, on the next line it says, if (mail($to, $subject, $body)). This basically means if it successfully sends the subject and body to the person then it will do something, which I will state next. The next line says echo("<p>Message successfully sent!</p>");. echo makes the text inside of the parentheses output onto the screen. This goes along with our if statement. So, if it sends the subject and body to the person it will say Message successfully sent! Now, look at the next line. It says else. The else function basically means that if the message was not successfully sent, then it will do something, which is on the next line. On the next line it says echo("<p>Message delivery failed...</p>");. This will output "Message Delivery Failed..." on to the screen. That is the end of this tutorial and explanation. Enjoy! RE: Tutorial and Explanation of How to Send an Email with PHP - 1234hotmaster - 02-15-2012 PHP Code: <? mail('someone@gmail.com','hi','example') ?>beat that length ![]() i did it in 1 line
RE: Tutorial and Explanation of How to Send an Email with PHP - Woody - 02-15-2012 (02-15-2012, 10:22 PM)1234hotmaster Wrote: Haha, I did it the long way to show how everything works. |