Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('config.php');
- require("class.PHPMailer.php"); //inclui o PHPMailer aqui
- // Sender Info
- $name = trim($_POST['name']);
- $email = trim($_POST['email']);
- $message = trim($_POST['message']);
- $err = "";
- // Check Info
- $pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$^";
- if (!preg_match_all($pattern, $email, $out)) {
- $err = MSG_INVALID_EMAIL; // Invalid email
- }
- if (!$email) {
- $err = MSG_INVALID_EMAIL; // No Email
- }
- if (!$message) {
- $err = MSG_INVALID_MESSAGE; // No Message
- }
- if (!$name) {
- $err = MSG_INVALID_NAME; // No name
- }
- if (!$err) {
- //send the email
- $mail = new PHPMailer();
- $mail->IsSMTP(); // set mailer to use SMTP
- $mail->Host = "mail.example.com;mail2.example.com"; // specify main and backup server
- $mail->SMTPAuth = true; // turn on SMTP authentication
- $mail->Username = "jswan"; // SMTP username
- $mail->Password = "secret"; // SMTP password
- $mail->From = $email;
- $mail->FromName = $name;
- $mail->AddAddress(TO_EMAIL);
- $mail->AddReplyTo($email, $name);
- $mail->Subject = SUBJECT;
- $mail->Body = $message;
- $sent = $mail->Send()
- if ($sent) {
- // If the message is sent successfully print
- echo "SEND";
- } else {
- // Display Error Message
- echo MSG_SEND_ERROR;
- }
- } else {
- echo $err; // Display Error Message
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement