Sending Emails

From Web Developer Network Wiki
Jump to: navigation, search

To simply send an email to a recipient in php simply use

<?php
mail('mort@blort.com','Subject','Message');
?>


To send an HTML email:

<?php
require_once 'Mail.php';
require_once 'Mail/mime.php';

$html = "<html>".
		"<body bgcolor='#ffffff'>".
			"<p>".
			"A comment has been submitted on {$do->submitdatetime}.".
			"</p>".$form->toHtml().
		"</body>".
	"</html>";							
$crlf = "\n";
$hdrs = array(
  'From'    => 'ucommxsrv1.unl.edu',
  'Subject' => 'Comments');

$mime = new Mail_mime($crlf);
$mime->setHTMLBody($html);
if (isset($_FILES['file_id'])
	&& is_uploaded_file($_FILES['file_id']['tmp_name'])
	&& $_FILES['file_id']['error']==UPLOAD_ERR_OK) {
	$mime->addAttachment($_FILES['file_id']['tmp_name'], $_FILES['file_id']['type'], $_FILES['file_id']['name']);
}

$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('sendmail');
$mail->send('mort@blort.com', $hdrs, $body);

?>
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox