php email function code example
Example 1: php mail
<?php
$to = $_POST['email'];
$subject = "Email Subject";
$message = 'Dear '.$_POST['name'].',<br>';
$message .= "We welcome you to be part of family<br><br>";
$message .= "Regards,<br>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Example 2: php mail
<?php
$to = '[email protected], [email protected]';
$subject = 'Birthday Reminders for August';
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Johny</td><td>10th</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'To: Mary <[email protected]>, Kelly <[email protected]>';
$headers[] = 'From: Birthday Reminder <[email protected]>';
$headers[] = 'Cc: [email protected]';
$headers[] = 'Bcc: [email protected]';
if(mail($to, $subject, $message, implode("\r\n", $headers))){
echo "success";
}else{
echo "Echec send email";
}
;
?>
Example 3: php mail
$mailtext = '<html>
<head>
<title>HTML-E-Mail mit PHP erstellen</title>
</head>
<body>
...
</body>
</html>
';
$empfaenger = "[email protected]";
$absender = "[email protected]";
$betreff = "Mail-Test - HTML-E-Mail mit PHP erstellen";
$antwortan = "[email protected]";
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=utf-8\r\n";
$header .= "From: $absender\r\n";
$header .= "Reply-To: $antwortan\r\n";
$header .= "X-Mailer: PHP ". phpversion();
mail( $empfaenger,
$betreff,
$mailtext,
$header);
echo "Mail wurde gesendet!";
Example 4: smtp in php mail function
<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
require_once "Mail.php";
$host = "ssl://smtp.dreamhost.com";
$username = "[email protected]";
$password = "your email password";
$port = "465";
$to = "[email protected]";
$email_from = "[email protected]";
$email_subject = "Subject Line Here:" ;
$email_body = "whatever you like" ;
$email_address = "[email protected]";
$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $email_body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>