3w PHP Your Source for PHP Source Code

16Jun/110

A simple class for mailing using PHPMailer SMTP Option.

This sample shows how you use the site_mail class within a function.
Notice that chaining is supported here, and makes things much faster in case you want to use the class to mail the webmaster errors from your script.
in this sample we are getting an email sent to us from the site's contact form.

<?
function mail_contact($data)
{
 
	$mail = new site_mail();
	$mail->from($data->email,$data->name)->subject($data->subject);
	$message = 'Sent from...'."\n".'Host: '.gethostbyaddr($_SERVER['REMOTE_ADDR'])."\n";
	$message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\n";
	$message .= 'Name: '.$data->name."\n";
	$message .= 'Email: '.$data->email."\n";
	if($data->link)
	{
		$message .= 'Link: '.$data->link."\n";
	}
	$message .= 'Message: '."\n".$data->message."\n";
 
	$mail->message($message)->html()->logo(LOGO_FILE);
	foreach ($conf->site->admin as $admin)
	{
		$mail->to($admin->email, $admin->name);
	}
	// If you need to debug and make sure your settings are good, uncomment the next line.
	//$mail->debug();
	$sent = $mail->send();
	return $sent;
}
?>

Download: Site Mail class for PHPMailer (1383)
Please comment and make any suggestions you wish.
Thank you.
Manny E.
3w.

Filed under: PHP Classes No Comments