Reputation: 35
I have a modal form that I am calling up on a page i am doing via an image click. the modal form comes up as it should, i can fill out the information, click submit and it goes to the "process.php" file to be emailed to me.
The process.php file will return that the email has been sent, but it never comes.
nothing echo's back either when it states the message is sent.
<a data-toggle="modal" data-target="#myModal" href="#"><img src="http://ashlardev.byethost17.com/images/shoplevel.png" class="img-square pull-right"></a>
<div class="modal fade custom-class" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Complete the form below to setup your <br>FREE account to view Le-Vel Products:</h4>
</div>
<div class="modal-body">
<form id="modal_feedback" method="POST" action="/process.php" accept-charset="UTF-8">
<p><label>Your Name<strong>*</strong><br>
<input type="text" autofocus required size="48" name="name" value=""></label></p>
<p><label>Email Address<strong>*</strong><br>
<input type="email" required title="Please enter a valid email address" size="48" name="email" value=""></label></p>
<p><label>Telephone<br>
<input type="tele" size="48" name="tele" value=""></label></p>
</form>
</div>
<div class="modal-footer">
*This information will not be shared with anyone other than Le-Vel.
<a href="/process.php" class="btn btn-success" type="submit" value="Send!" id="submit">Submit</a>
<a href="index5.html" class="btn btn-success" data-dismiss="modal">Nah.</a>
</div>
<?php
require_once('PHPMailerAutoload.php');
require_once('class.phpmailer.php');
require_once('class.smtp.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.openmailbox.org"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = false; // enable SMTP authentication
$mail->Host = "smtp.openmailbox.org"; // sets the SMTP server
$mail->SMTPSecure = 'TLS'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
$mail->Username = "username"; // SMTP account username
$mail->Password = "password"; // SMTP account password
//add the recipient's address here
$myemail = '[email protected]';
$mail->addAddress('[email protected]', 'Ford Christopher');
//grab named inputs from html then post to #thanks
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$tele = strip_tags($_POST['tele']);
$body = "this is the body of my message: $name, $email, $tele";
$email_subject = "Le-Vel Free Account Information";
//generate email and send!
$headers = 'From: '.$email"\r\n".
'Reply-To: '.$email"\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($myemail, $email_subject, $body, $headers);
}
if($mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
echo $name;
echo $email;
echo $tele;
echo $body;
} else {
echo 'Message has been sent';
echo $name;
echo $email;
echo $tele;
echo $body;
}
?>
Upvotes: 1
Views: 691
Reputation: 13128
There are a range of things wrong. Firstly, don't ever suppress your functions with @
. Rather test it properly and handle it:
if(!mail($myemail, $email_subject, $body, $headers)) {
echo "failed";
}
Secondly, you're if($mail->send())
condition is wrong. You have them the wrong way around:
if($mail->send()) {...
== TRUE
if(!$mail->send()) {...
== FALSE
So you'd want your comparison to look like this:
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
//... the rest..
} else {
echo 'Mail sent successfully';
}
It isn't sending due to the fact that your "submit" is simply a <a>
link to your process.php
page.
You need to re-structure your form properly otherwise no input elements will be submitted. Hence why no mail will be sent.
<div class="modal fade custom-class" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Complete the form below to setup your <br>FREE account to view Le-Vel Products:</h4>
</div>
<form id="modal_feedback" method="POST" action="/process.php" accept-charset="UTF-8">
<div class="modal-body">
<p><label>Your Name<strong>*</strong><br>
<input type="text" autofocus required size="48" name="name" value=""></label></p>
<p><label>Email Address<strong>*</strong><br>
<input type="email" required title="Please enter a valid email address" size="48" name="email" value=""></label></p>
<p><label>Telephone<br>
<input type="tele" size="48" name="tele" value=""></label></p>
</div>
<div class="modal-footer">
*This information will not be shared with anyone other than Le-Vel.
<input type="submit" class="btn btn-success" name="submit" value="Send!" id="submit">
<a href="index5.html" class="btn btn-success" data-dismiss="modal">Nah.</a>
</div>
</form>
</div>
</div>
</div>
You'll notice how I've moved the form element to encase the .modal-body
& .modal-footer
; allowing you to actually have a submit
input element.
Upvotes: 1