June 3, 201115 yr I'm trying to get a contact form up and running using AJAX and phpmailer on my Site but i am having some trouble. This is the ajax i use when the form is submitted $(function() { $("#contact_form").submit(function() { var name = $("input#name").val(); var email = $("input#email").val(); var phone = $("input#phone").val(); var reason = $("input#contact_reason").val(); var message = $("input#message").val(); var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&reason=' + reason + '&message=' + message; $.ajax({ type: "POST", url: "/wp-content/themes/Portfolio/js/process.php", data: dataString, success: function() { $('#contact_form').html("<div id='message'></div>"); $('#message').html("<h2 class='no-margin-title'>Contact Form Submitted!</h2>"); $('#message').append("<img id='contact-tick' src='/wp-content/themes/Portfolio/images/tick.gif'/>") .append("<h3>I will be in touch <span class='blog-sub-span'>soon</span></h3>") .hide() .fadeIn(1500, function() { }); } }); return false; }); }); And this is the process.php page i have used to set up the phpmailer <?php if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) { $name = stripslashes(strip_tags($_POST['name'])); } else {$name = 'No name entered';} if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) { $email = stripslashes(strip_tags($_POST['email'])); } else {$email = 'No email entered';} if ((isset($_POST['phone'])) && (strlen(trim($_POST['phone'])) > 0)) { $phone = stripslashes(strip_tags($_POST['phone'])); } else {$phone = 'No phone entered';} if ((isset($_POST['reason'])) && (strlen(trim($_POST['reason'])) > 0)) { $name = stripslashes(strip_tags($_POST['reason'])); } else {$name = 'No reason entered';} if ((isset($_POST['message'])) && (strlen(trim($_POST['message'])) > 0)) { $name = stripslashes(strip_tags($_POST['message'])); } else {$name = 'No message entered';} ob_start(); ?> <html> <head> <style type="text/css"> </style> </head> <body> <table width="550" border="1" cellspacing="2" cellpadding="2"> <tr bgcolor="#eeffee"> <td>Name</td> <td><?=$name;?></td> </tr> <tr bgcolor="#eeeeff"> <td>Email</td> <td><?=$email;?></td> </tr> <tr bgcolor="#eeffee"> <td>Phone</td> <td><?=$phone;?></td> </tr> <tr bgcolor="#eeffee"> <td>Reason</td> <td><?=$reason;?></td> </tr> <tr bgcolor="#eeffee"> <td>Message</td> <td><?=$message;?></td> </tr> </table> </body> </html> <? $body = ob_get_contents(); require("phpmailer.php"); $mail = new PHPMailer(); $mail->From = "ben.gibson.2011@gmail.com"; $mail->FromName = "Contact Form"; $mail->AddAddress("email_address@example.com","Name 1"); $mail->AddAddress("another_address@example.com","Name 2"); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Subject = "Demo Form: Contact form submitted"; $mail->Body = $body; $mail->AltBody = "This is the text-only body"; if(!$mail->Send()) { $recipient = 'your_email@example.com'; $subject = 'Contact form failed'; $content = $body; mail($recipient, $subject, $content, "From: mail@yourdomain.com\r\nReply-To: $email\r\nX-Mailer: DT_formmail"); exit; } ?> This is the first time i have used phpMailer and im doing something wrong can anyone see what iv done wrong or make a better suggestion to send the form to my mail Thanks for any help
Create an account or sign in to comment