3w PHP Your Source for PHP Source Code


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();
	$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";
		$message .= 'Link: '.$data->link."\n";
	$message .= 'Message: '."\n".$data->message."\n";
	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.
	$sent = $mail->send();
	return $sent;

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

Filed under: PHP Classes No Comments