//SMTP server settings $host = "smtp.host.com"; $port = "587"; $username = ""; $password = ""; $messageBody = ""; if($_POST['name']!='false'){ $messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n"; $messageBody .= '<br>' . "\n"; } if($_POST['email']!='false'){ $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n"; $messageBody .= '<br>' . "\n"; }else{ $headers = ''; } if($_POST['state']!='false'){ $messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n"; $messageBody .= '<br>' . "\n"; } if($_POST['phone']!='false'){ $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n"; $messageBody .= '<br>' . "\n"; } if($_POST['fax']!='false'){ $messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n"; $messageBody .= '<br>' . "\n"; } if($_POST['message']!='false'){ $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n"; } if($_POST["stripHTML"] == 'true'){ $messageBody = strip_tags($messageBody); } if($host=="" or $username=="" or $password==""){ $owner_email = $_POST["owner_email"]; $headers = 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n"; $subject = 'A message from your site visitor ' . $_POST["name"]; try{ if(!mail($owner_email, $subject, $messageBody, $headers)){ throw new Exception('mail failed'); }else{ echo 'mail sent'; } }catch(Exception $e){ echo $e->getMessage() ."\n"; } }else{ require_once 'Mail.php'; $to = $_POST["owner_email"]; $subject = 'A message from your site visitor ' . $_POST["name"]; $headers = array ( 'From' => 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n", 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory( 'smtp', array ( 'host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $messageBody); try{ if(PEAR::isError($mail)){ echo $mail->getMessage(); }else{ echo 'mail sent'; } }catch(Exception $mail){ echo $mail->getMessage() ."\n"; } } ?> <?php $sbj_visitor='Newsletter subscription confirmation email from '; $sbj_owner='Newsletter subscription request from '; $header="Content-type: text/html; charset=utf-8 \r\n"; $name=$_POST['name']; $email=$_POST['email']; $owner=$_POST['owner']; $owner_email=$_POST['owner_email']; $sitename=$_POST['sitename']; $sbj_visitor.=$sitename; $sbj_owner.=$sitename; $msg_visitor='<a href="http://'.$sitename.'">'.$sitename.'</a>'."\n".'<br>'.'Hi, '.$name."\n".'<br>'.'Thank you for subscribing to our newsletter!'; $msg_owner='<a href="http://'.$sitename.'">'.$sitename.'</a>'."\n".'<br>'.'This email has been sent via newsletter subscription form on your website. A new visitor would like to be added to your website\'s newsletter:'."\n".'<br>'.'Visitor name: '.$name."\n".'<br>'.'Visitor email: '.$email."\n".'<br>'.'Please add him (her) to your newsletter list.'; try{ if(!mail($email,$sbj_visitor,$msg_visitor,$header.'From: '.$owner_email)){ throw new Exception('mail failed'); }else{ echo "mail to visitor sent \n"; } }catch(Exception $e){ echo $e->getMessage() ."\n"; } try{ if(!mail($owner_email,$sbj_owner,$msg_owner,$header.'From: '.$email)){ throw new Exception('mail failed'); }else{ echo "mail to owner sent"; } }catch(Exception $e){ echo $e->getMessage() ."\n"; } ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)