Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('phpmailer/PHPMailerAutoload.php');
- $toemails = array();
- $toemails[] = array(
- 'email' => 'recipient@domain.com', // Your Email Address
- 'name' => 'Recipient Name' // Your Name
- );
- $mail = new PHPMailer();
- // If you intend you use SMTP, add your SMTP Code after this Line
- $mail->IsSMTP();
- $mail->Host = "mail.domain.com";
- $mail->SMTPDebug = 2;
- $mail->SMTPAuth = true;
- $mail->Port = 25;
- $mail->Username = "forms@domain.com";
- $mail->Password = "PaSsWoRd";
- if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
- if( $_POST['template-contactform-email'] != '' ) {
- $name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
- $email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
- $phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
- $company = isset( $_POST['template-contactform-company'] ) ? $_POST['template-contactform-company'] : '';
- $subject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : '';
- $message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';
- $subject = isset($subject) ? $subject : 'New Message From Contact Form';
- $botcheck = $_POST['template-contactform-botcheck'];
- if( $botcheck == '' ) {
- $mail->SetFrom( $email , $name );
- $mail->AddReplyTo( $email , $name );
- foreach( $toemails as $toemail ) {
- $mail->AddAddress( $toemail['email'] , $toemail['name'] );
- }
- $mail->Subject = $subject;
- $name = isset($name) ? "Name: $name<br><br>" : '';
- $email = isset($email) ? "Email: $email<br><br>" : '';
- $phone = isset($phone) ? "Phone: $phone<br><br>" : '';
- $company = isset($company) ? "Firm or Company Name: $company<br><br>" : '';
- $message = isset($message) ? "Message: n$message<br><br>" : '';
- $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';
- $body = "$name $email $phone $company $message $referrer";
- $mail->MsgHTML( $body );
- $sendEmail = $mail->Send();
- if( $sendEmail == true ):
- //ORIGINAL ECHO OF SUCCESS MESSAGE
- //echo '{ "alert": "success", "message": "' . $message_success . '" }';
- //SWITCH TO REDIRECT
- header("Location: ../thank-you.php");
- else:
- echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }';
- endif;
- } else {
- echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! Clean yourself Botster.!" }';
- }
- } else {
- echo '{ "alert": "error", "message": "Please <strong>Fill up</strong> all the Fields and Try Again." }';
- }
- } else {
- echo '{ "alert": "error", "message": "An <strong>unexpected error</strong> occured. Please Try Again later." }';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement