I have searched and researched high and low and I am still unable to find an answer.
I am using PHP Mailer that came with a theme we purchased (version 5.2.1). I am trying to figure out how to capture the phone number and send it along with the other data in the email that is sent.
The Form:
<form method="post" action="#" id="contactForm">
<div class="input-prepend" style="margin-left:0px;margin-right:0px">
<input class="input-xlarge required" id="name" type="text" placeholder="Name (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="email" type="text" placeholder="Email (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="phone" name="phone" type="text" placeholder="Phone (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="subject" type="text" placeholder="Subject (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="children-3-7" type="text" placeholder="Number of Children (Age 3 - 7) (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="children-7-14" type="text" placeholder="Number of Children (Age 7 - 14) (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<input class="input-xlarge required" id="adults" type="text" placeholder="Number of Adults (Required)" />
</div>
<div class="input-prepend" style="margin-left:0px">
<textarea name="message-input" id="message" class="span12 required" cols="5" rows="5" placeholder="Message (Required)" style="margin-left:0px"></textarea>
</div>
<div class="clearfix" style="margin:10px 0px 0px 0px">
<span>Reset Form</span>
<span>Send Message</span>
<!-- Processing data trick -->
<div id="loadingForm">
<img src="images/normal/ajax-small.gif" alt="ajax-small" />
</div>
<!-- Processing data trick -->
</div>
<br />
<div class="clearfix">
<!-- contact notice -->
<div class="alert alert-block fade" id="contact-notice">
<span><strong>Warning!</strong> All fields above are required to send the message properly.</span>
</div>
<!-- contact notice -->
</div>
</form>
The PHP
<?php
require_once("class.phpmailer.php");
send();
function send(){
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'host.com';
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "tls";
$mailer->Port = 587;
$mailer->CharSet="utf-8";
$mailer->IsHTML(true);
$mailer->Username = 'mail-bot#mail.com';
$mailer->Password = 'PASSWORD';
$mailer->FromName = $_POST['name'];
$mailer->From = $_POST['email'];
$mailer->AddAddress('ADDRESS','NB=AME');
$mailer->Subject = $_POST['subject'];
$mailer->MsgHTML = $_POST['message'];
$phone = $_POST['phone'];
/**$mailer->Age1 = $_POST['children-3-7'];
//$mailer->Age2 = $_POST['children-7-14'];
//$mailer->Age3 = $_POST['adults'];**/
$mailer->Body = "From : ".$_POST['name']."<br /> E-mail : ".$_POST['email']."<br /> Subject : ".$_POST['subject']."<br />Message : ".$_POST['message']."<br />Phone : $phone";
if(!$mailer->Send()){
echo "error^Message could not be sent.<br />";
echo "Mailer Error: " . $mailer->ErrorInfo;
exit;
}
else{
echo "ok^Message sent successfully!";
}
}
?>
As you can see I am attempting to use
$phone = $_POST['phone'];
to extract the phone number and then adding it to the message body by using
$mailer->Body = "From : ".$_POST['name']."<br /> E-mail : ".$_POST['email']."<br /> Subject : ".$_POST['subject']."<br />Message : ".$_POST['message']."<br />Phone : $phone";
To inject the phone number
I have also tried injecting in the following way
$mailer->Body = "From : ".$_POST['name']."<br /> E-mail : ".$_POST['email']."<br /> Subject : ".$_POST['subject']."<br />Message : ".$_POST['message']."<br />Phone: ".$_POST['phone'];
Any help will be greatly appreciated.
It appears as if there was a secondary validation sitting in our main .js file that was validating empty fields before posting them via ajax. Phone number needed to be added in there before it posted it and I can now successfully capture the data.
Thanks for your help!
Related
I am using Ampps on Mac and trying to send an email using php from a contact form however I do not receive the mail and when the form is submitted it redirects me to the file page resulting in a blank display
my form :
<form action="email.php" method="post">
<div class="col-md-6 w3_agileits_contact_left">
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-22" name="Name" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-22">
<span class="input__label-content input__label-content--akira">Your name</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="email" id="input-23" name="Email" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-23">
<span class="input__label-content input__label-content--akira">Your email</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-24" name="Subject" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-24">
<span class="input__label-content input__label-content--akira">Your subject</span>
</label>
</span>
</div>
<div class="col-md-6 w3_agileits_contact_right">
<div class="w3_agileits_contact_right1">
<textarea name="Message" id="Message" placeholder="Your comment here..." required=""></textarea>
</div>
<div class="w3_agileits_contact_right2">
<input type="submit" value="Send">
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</form>
my File :
$email = $_POST['Email'];
$name = $_POST['Name'];
$to = "lucvanrooyen#gmail.com";
$subject = $_POST['Subject'];
$userMessage =$_POST['Message'];
$headers = "From: $email\n";
$message = "$name has sent you the following message.\n
Message: $userMessage";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: lucvanrooyen#gmail.com\n";
$usermessage = "Thank you for your enquiry we will be in touch.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
The code you have shown is not enough to debug your problem.
If you are using the mail method which is built into the standard library, read this answer to find out a few troubleshooting steps you could follow.
If you are and are still finding it difficult to use, then you could consider using one of the PHP emailing solutions like -
PHPMailer
SwiftMailer
Please check your form tag. there is no opening tag for form
<form action="email.php" method="post">
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I haven't written code in years, so I am going off old code from a project that is over 5 years old, so I am not surprised that it doesn't work; I would like some pointers on how to make it work, please.
Here is what I have in my HTML email form --
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
and here is what my PHP looks like --
<?php
if(isset($_POST['send'])) {
// Prepare the email
$to = ''foryourdayformals#gmail.com ';
$name = $_POST['contact_name'];
$mail_from = $_POST['contact_email'];
$subject = 'Message sent from website';
$message = $_POST['contact_message'];
$header = "From: $name <$mail_from>";
// Send it
$sent = mail($to, $subject, $message, $header);
if($sent) {
echo 'Your message has been sent successfully! Return to For Your Day, LLC Website';
} else {
echo 'Sorry, your message could not send. Please use direct email link on Contact Us page (below the map). Return to For Your Day, LLC Website';
}
}
?>
Any help is GREATLY appreciated! Thanks!
update
$to = ''foryourdayformals#gmail.com ';
to
$to = 'foryourdayformals#gmail.com';
and need to add name attribute for form . This update your form
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" name="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" name="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" name="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary" name ="send">Send</button>
</form>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
This is code of my form.
<form method="post" action="mailer.php" id="contactfrm">
<div class="col-sm-4">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter name" title="Please enter your name (at least 2 characters)">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" id="email" placeholder="Enter email" title="Please enter a valid email address">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="comments">Message</label>
<textarea name="message" class="form-control" id="comments" cols="3" rows="5" placeholder="Enter your message…" title="Please enter your message (at least 10 characters)"></textarea>
</div>
<button name="submit" type="submit" class="btn btn-lg btn-primary" id="submit">Submit</button>
<div class="result"></div>
</div>
</form>
Here My mailer.php
<?php
$replyemail="my email";
$name = $_POST["name"];
$email = $_POST["email"];
$thesubject = "Project With Me Query";
$themessage = $_POST["message"];
$success_sent_msg='<p align="center"><strong> </strong></p>
<p align="center"><strong>Your message has been successfully sent to My Email<br>
</strong> and I will reply as soon as possible.</p>
<p align="center">A copy of your query has been sent to you.</p>
<p align="center">Thank you for contacting Me.</p>';
$replymessage = "Hi $name
Thank you for your email.
We will endeavour to reply to you shortly.
Please DO NOT reply to this email.
Below is a copy of the message you submitted:
--------------------------------------------------
Subject: $thesubject
Query:
$themessage
--------------------------------------------------
Thank you";
$themessage = "name: $name \nQuery: $themessage";
mail("$replyemail",
"$thesubject",
"$themessage",
"From: $email\nReply-To: $email");
mail("$email",
"Receipt: $thesubject",
"$replymessage",
"From: $replyemail\nReply-To: $replyemail");
echo $success_sent_msg;
echo '<script>setTimeout(function(){location.href="index.php"} , 5000); </script>';
?>
I am unable to figure out what wrong I've done.
whenever i fill out information in for a Success Message displayed. but i didn't get any email of that information.
can someone fix this existing code or provide me a new mailer code?
Your form
<form method="post" action="1.php" id="contactfrm">
<div class="col-sm-4">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter name" title="Please enter your name (at least 2 characters)">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" id="email" placeholder="Enter email" title="Please enter a valid email address">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="comments">Message</label>
<textarea name="message" class="form-control" id="comments" cols="3" rows="5" placeholder="Enter your message…" title="Please enter your message (at least 10 characters)"></textarea>
</div>
<button name="submit" type="submit" class="btn btn-lg btn-primary" id="submit">Submit</button>
<div class="result"></div>
</div>
</form>
Your php code with smtp
<?php
if(isset($_POST["submit"])){
$replyemail="my email";
$name = $_POST["name"];
$email = $_POST["email"];
$thesubject = "Project With Me Query";
$themessage = $_POST["message"];
$success_sent_msg='<p align="center"><strong> </strong></p>
<p align="center"><strong>Your message has been successfully sent to My Email<br>
</strong> and I will reply as soon as possible.</p>
<p align="center">A copy of your query has been sent to you.</p>
<p align="center">Thank you for contacting Me.</p>';
$replymessage = "Hi $name
Thank you for your email.
We will endeavour to reply to you shortly.
Please DO NOT reply to this email.
Below is a copy of the message you submitted:
--------------------------------------------------
Subject: $thesubject
Query:
$themessage
--------------------------------------------------
Thank you";
$themessage = "name: $name \nQuery: $themessage";
include "PHPMailer_5.2.4/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "yourusername#gmail.com";
$mail->Password = "yourgmailpassword";
$mail->AddReplyTo($replymessage, "Reply name");
$mail->AddAddress($email,'ashu');
$mail->Subject = "SMTP Receivced";
$mail->Body = "<b>Succesfully SMTP Receivced</b>";
$mail->MsgHTML($success_sent_msg);
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = 'index.php';
$crlf = "\n";
$hdrs = array(
'From' => 'you#yourdomain.com',
'Subject' => 'Test mime message'
);
if($mail->send($hdrs))
{
echo "<script> alert('Successfully Mailed');window.location = '';</script>";
}
else{
echo "Mailed Error: " . $mail->ErrorInfo;
}
}
//echo '<script>setTimeout(function(){location.href="pra-2.php"} , 5000); </script>';
?>
I've got 2 contact forms on a site. One is for simple contact-us and the other is for a registration. I've got them pointing to two different php and js files. The contact-us form is working, but I can't get the registration form to work. Here's the php:
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phoneNumber']) ||
empty($_POST['childFirstName']) ||
empty($_POST['childLastName']) ||
empty($_POST['childAge']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['phoneNumber'];
$message = $_POST['childFirstName'];
$message = $_POST['childLastName'];
$message = $_POST['childAge'];
// create email body and send it
$to = 'lloyd.leeiv#yahoo.com';
$email_subject = "Contact form submitted by: $name";
$email_body = "You have received a new message. \n\n".
" Here are the details:\n \n Parent/Guardian Name: $name \n ".
"Email: $email_address \n Phone: $phoneNumber \n Child's Name: $childFirstName $childLastName \n Age: $childAge";
$headers = "From: JNGSO#jngso.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
And the HTML:
<form name="sentMessage" class="well" id="contactForm" novalidate>
<p>Parent/Guardian Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control"
placeholder="Parent/Guardian Name" id="name" required
data-validation-required-message="Please enter your name" />
<p class="help-block"></p>
</div>
</div>
<p>Email Address</p>
<div class="control-group">
<div class="controls">
<input type="email" class="form-control" placeholder="Email"
id="email" required
data-validation-required-message="Please enter your email" />
</div>
</div>
<p>Phone Number</p>
<div class="control-group">
<div class="controls">
<input type="number" class="form-control" placeholder="Phone Number"
id="phoneNumber" required
data-validation-required-message="Please enter your phone number" />
</div>
</div>
<p>Child's First Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control" placeholder="Child's First Name"
id="childFirstName" required
data-validation-required-message="Please enter your child's first name" />
</div>
</div>
<p>Child's Last Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control" placeholder="Child's Last Name"
id="text" required
data-validation-required-message="Please enter your child's last name" />
</div>
</div>
<p>Child's Age</p>
<div class="control-group">
<div class="controls">
<input type="number" class="form-control" placeholder="Child's Age"
id="number" required
data-validation-required-message="Please enter your child's age" />
</div>
</div>
<p>Boy or Girl?</p>
<div class="control-group">
<label class="radio-inline">
<input type="radio" name="boyGirl" id="boy" value="Boy"> Boy
</label>
<label class="radio-inline">
<input type="radio" name="boyGirl" id="girl" value="Girl"> Girl
</label>
</div>
<div id="success"> </div>
<button type="submit" class="btn btn-lg btn-success pull-right">Send</button><br />
</form>
I've got the proper script links on the page (changed the name to point to the correct js file) and in the js file I'm pointing to the correct php url. Like I said, it works with the contact-us form but not this one. I can't figure out what I'm missing!
Okay, so I threw this question up in desperation (because I'm new to php and I didn't think I could solve it). After carefully examining it, it's actually pretty simple! doh!
I just had to make sure all of the id's were labeled, all of the var were accounted for and everything matched up in my php. For example, you can see above I have:
....
$message = $_POST['phoneNumber'];
$message = $_POST['childFirstName'];
$message = $_POST['childLastName'];
$message = $_POST['childAge'];
....
in my php where I should have each of those labeled differen't (not each one as $message).
I'm sorry if this wasted anyone's time, but hopefully someone can find this useful.
I've been looking around everywhere and cannot seem to find how to make this work - it is simply not sending an email to my address. Here is my HTML form:
<form id="contactMe" name="contact" method="post" novalidate="novalidate">
<fieldset>
<label for="name" id="name">Name<span class="required">*</span></label>
<input type="text" name="name" id="name" size="30" value="" required="">
<label for="email" id="email">Email<span class="required">*</span></label>
<input type="text" name="email" id="email" size="30" value="" required="">
<label for="phone" id="phone">Phone</label>
<input type="text" name="phone" id="phone" size="30" value="">
<label for="Message" id="message">Message<span class="required">*</span></label>
<textarea name="message" id="message" required=""></textarea>
<label for="Answer" id="answer">Name the house pet that says “<i>woof</i>“<span class="required">*</span></label>
<input type="text" name="answer" value="" required=""></br>
<input id="submit" type="submit" name="submit" value="Send">
</fieldset>
<div id="success">
<span class="green textcenter">
<p>Your message was sent successfully! I will be in touch as soon as I can.</p>
</span>
</div> <!-- closes success div -->
<div id="error">
<span><p>Something went wrong, try refreshing and submitting the form again.</p></span>
</div> <!--close error div-->
</form>
and here is my PHP saved as mailer.php:
<?php
$to = "someone#gmail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$headers = "From: $from";
$subject = "You have a message from your.";
$fields = array();
$fields{"name"} = "name";
$fields{"email"} = "email";
$fields{"phone"} = "phone";
$fields{"message"} = "message";
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
mail("maytee.kneitz#gmail.com",$subject,$message,"From: $from\n");
echo 'Mail sent';
?>
This is my first shot at working on a mailer / contact form, so sorry if it's a blatant problem. I just can't seem to find it. Any guidance would be appreciated.
I do have validation in my scripts (not posted here).
You don't have a form action defined. Try this:
<form id="contactMe" name="contact" method="post" action="mailer.php" novalidate="novalidate">
By default, the form will be submitted to its current location unless otherwise specified. In your case, point it to wherever your mail script is located