How to send mail using php
What is PHP mail function ?
PHP mail is the PHP function that is used for send emails with PHP script.
The mail function follows the following parameters;
- Email address
- Subject
- Message
- CC or BC email address
- Let users contact you via email by providing a contact us form on the website that emails the provided content.
- Developers can use it to receive system errors by email
- You can use it to email your newsletter subscribers.
- You can use it to send password reset links to users who forget their passwords
- You can use it to email activation/confirmation links. This is useful when registering users and verifying their email addressesLet’s now look at an example that sends a simple mail.
<?php $to_email = 'info@samtechnology.org'; $subject = 'Testing PHP Mail'; $message = 'This mail is sent using the PHP mail function'; $headers = 'From: noreply@samtechnology.org'; if(mail($to_email,$subject,$message,$headers)); {
echo"Mail Send Successfully..";
} else {echo"Email Sending Failed.!";
} ?>
sending email trough html form :<form action="" method="post"> <table width="400" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="29%" class="bodytext">Your name:</td> <td width="71%"><input name="name" type="text" id="name" size="32"></td> </tr> <tr> <td class="bodytext">Email address:</td> <td><input name="email" type="text" id="email" size="32"></td> </tr> <tr> <td class="bodytext">Comment:</td> <td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td> </tr> <tr> <td class="bodytext"> </td> <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form>
<?php
if ($_POST["email"])
{
$ToEmail = 'youremail@site.com';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
echo"Success";
?>
No comments