Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Felipe
- * Date: 29/07/2016
- * Time: 07:41
- */
- //SMTP needs accurate times, and the PHP time zone MUST be set
- //This should be done in your php.ini, but this is how to do it if you don't have access to that
- date_default_timezone_set('Etc/UTC');
- require '/lib/PHPMailerAutoload.php';
- //Create a new PHPMailer instance
- $mail = new PHPMailer;
- //Tell PHPMailer to use SMTP
- $mail->isSMTP();
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 2;
- //Ask for HTML-friendly debug output
- $mail->Debugoutput = 'html';
- //Set the hostname of the mail server
- $mail->Host = "mail.example.com";
- //Set the SMTP port number - likely to be 25, 465 or 587
- $mail->Port = 25;
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication
- $mail->Username = "yourname@example.com";
- //Password to use for SMTP authentication
- $mail->Password = "yourpassword";
- //Set who the message is to be sent from
- $mail->setFrom('from@example.com', 'First Last');
- //Set an alternative reply-to address
- $mail->addReplyTo('replyto@example.com', 'First Last');
- //Set who the message is to be sent to
- $mail->addAddress('whoto@example.com', 'John Doe');
- //Set the subject line
- $mail->Subject = 'PHPMailer SMTP test';
- //Read an HTML message body from an external file, convert referenced images to embedded,
- //convert HTML into a basic plain-text alternative body
- $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
- //Replace the plain text body with one created manually
- $mail->AltBody = 'This is a plain-text message body';
- //Attach an image file
- $mail->addAttachment('images/phpmailer_mini.png');
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $errors = array();
- $headers = "From: " . "noreply@colourtone-masterbatch.co.uk" . "\r\n";
- $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
- $headers .= "MIME-Version: 1.0\r\n";
- $firstname = (isset($_POST['firstname']) && ctype_alpha($_POST['firstname'])) ? $_POST['firstname'] : $errors[] = "Invalid First Name";
- $secondname = (isset($_POST['secondname']) && ctype_alpha($_POST['secondname'])) ? $_POST['secondname'] : $errors[] = "Invalid Second Name";
- $job = (isset($_POST['job'])) ? $_POST['job'] : $errors[] = "Invalid Job";
- $address1 = (isset($_POST['address1'])) ? $_POST['address1'] : $errors[] = "Invalid Address 1";
- $address2 = (isset($_POST['address2'])) ? $_POST['address2'] : $errors[] = "Invalid Address 2";
- $phone = (isset($_POST['phone'])) ? $_POST['phone'] : $errors[] = "Invalid Phone";
- $message = "<html><body>";
- $message .= "<p>
- A visitor to the Vynacol website has requested a brochure! Their recorded details are:<br><br>
- First Name: $firstname<br>
- Second Name: $secondname<br>
- Address Line 1: $address1<br>
- Contact Number: $phone<br>
- </p>";
- $message .= "</body></html>";
- if(empty($errors)) {
- if ($mail->send())
- $messages["success"] = "eMail sent!";
- else
- $messages["error"][] = "Something went wrong. Please contact site administrator." . $mail->ErrorInfo;;
- } else {
- $messages["error"] = $errors;
- }
- // Print the JSON!
- print(json_encode($messages));
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement