PHP contact form messages not receiving - php

Hi I have simple contact form for email on my site, and the form works including the success of a message sent,however, I am not receiving email to the designated webmail server. I am running the latest PHP. Do some web servers cache mail or is there some error in this code I am not seeing.
<?php
$EmailFrom = "email#mydomain.com";
$EmailTo = "email#mydomain.com";
$Subject = "Contacting Me";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Thought:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Transmit" class="submit-button" />
</form>
<div style="clear: both;"></div></div>

Sending mail is more complicated than just running the mail() command, you need to take a look at the php.ini settings for the email configuration and continue troubleshooting from there.
If you are running on a host that does not configure the mail() function to run, you can try using the following opensource mailer:
PHPMailer
What you can try is to use the examples provided and run from your local development stack (XAMPP, MAMP, WAMP) connected from your home, you should be able to receive mail if configured correctly.
Once it is OK, you can try it on the server, it should send as well, if not, check that the outgoing port for sending mail is not blocked.
Alternative to using PHPMailer, you can look for a simple PHP mailer and try those out as well.

Don't use print "<meta http-equiv=\"refresh\"... because during testing, it caused an endless loop while sending multiple copies of the same Email.
Use header('Location: ...'); instead, along with exit;.
Plus, all your <meta http-equiv=\"refresh\" have generated a parse error.
Working example (tested with Email successfully received):
<?php
$EmailFrom = "email#mydomain.com";
$EmailTo = "email#mydomain.com";
$Subject = "Contacting Me";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
// echo "error 1";
header('Location: error.htm');
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
header('Location: http://www.example.com/');
exit;
}
else{
header('Location: error.htm');
exit;
}
?>

i think its the mail function headers issue.
http://php.net/manual/en/function.mail.php
http://php.net/manual/en/function.mail.php

Related

php contact form was not working and not redirecting to success page

whats wrong in my code?
In HTML, I have taken form and i have created heading3 and i taken two inputs for name and email and i written textarea for message at last i taken another input is for submit and i closed the form tag.
<form method="post" action="contactengine.php">
<h3>Message Me</h3>
<input type="text" name="Name" id="Name" placeholder="Enter Name" required>
<input type="email" name="Email" id="Email" placeholder="Enter Email" required>
<textarea name="Message" id="Message" placeholder="Your Message"> </textarea>
<input type="submit" name="submit" value="Send Now" class="submit-button">
</form>
<?php
$EmailFrom = "xyz#gmail.com"; //your first email from where you want to send email
$EmailTo = "abc#gmail.com"; //your second email where you want to receive contact form content
$Subject = $_POST['Name']." Contacted you from your portfolio site"; //mail subject
$Name = Trim(stripslashes($_POST['Name'])); //getting name from html page
$Email = Trim(stripslashes($_POST['Email'])); //getting email from html page
$Message = Trim(stripslashes($_POST['Message'])); //getting message from html page
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
I would try this:
// send email
$success = mail($EmailTo, $Subject, $Body, "From:" . $EmailFrom);

Trouble sending email through contact form with php [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 6 years ago.
I've never worked with php before and am trying to make my contact form functional with the help of some php code I acquired through google.
First off do I need to link it to my html page somehow (like css/ javascript) or does it work fine if it shares the same folder?
I have modified the names of certain parts to match the names in my html but am unable to get it to work. When I click the submit button I get a page saying...
"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Company: "; $Body .= $Company; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Deadline: "; $Body .= $Dealine; $Body .= "\n"; $Body .= "Interested: "; $Body .= $Interested; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print ""; } else{ print ""; } ?>
The php code is as follows.
<?php
$EmailFrom = "c#c.co.nz";
$EmailTo = "c#c.co.nz";
$Subject = "contact-form";
$Name = Trim(stripslashes($_POST['Name']));
$Company = Trim(stripslashes($_POST['Company']));
$Email = Trim(stripslashes($_POST['Email']));
$Deadline = Trim(stripslashes($_POST['Dealine']));
$Interested = Trim(stripslashes($_POST['Interested']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Deadline: ";
$Body .= $Dealine;
$Body .= "\n";
$Body .= "Interested: ";
$Body .= $Interested;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-thanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Here is my html
<div role="form" class="form-wrapper">
<form name="contact-f" action="contact-form.php" method="post">
<div class="f-width">
<div class="f-col-1 f-group-1"><input type="text" name="Name" class="c-back input-t f-col-1" placeholder="Name" /></div>
<div class="f-col-1 f-group-2"><input type="email" name="Company" class="c-back input-t f-col-1" placeholder="Company Name" /></div>
<div class="f-col-1 f-group-1"><input type="text" name="Email" class="c-back input-t f-col-1" placeholder="Email Address" /></div>
<div class="f-col-1 f-group-2"><select name="Deadline" class="c-back input-t f-col-1"><option class="opt-f">Do you have a Deadline?</option><option value="Not yet" class="opt-f">Not yet</option><option value="Less than 1 Month" class="opt-f">Less than 1 Month</option><option value="2-3 Months" class="opt-f">2-3 Months</option><option value="3-6 Months" class="opt-f">3-6 Months</option><option value="6+ Months" class="opt-f">6+ Months</option></select></div>
<div class="f-col-2 f-group-3"><select name="Interested" class="c-back input-t f-col-2"><option class="opt-f">What are you interested in?</option><option value="Branding" class="opt-f">Branding</option><option value="Print Design" class="opt-f">Print Design</option><option value="Illustration" class="opt-f">Illustration</option><option value="Website / UI Design" class="opt-f">Website / UI Design</option><option value="Literature" class="opt-f">Literature</option><option value="Video Editing" class="opt-f">Video Editing</option><option value="Other" class="opt-f">Other</option></select></div>
<div class="f-col-3 f-group-4"><textarea name="Message" class="c-back input-t message-f f-col-3" placeholder="Describe your project..."></textarea></div>
<div class="f-submit f-group-5"><input type="Submit" name="Submit" value="Send" class="form-btn" /></div>
</div></form></div>
(And yes I have created the contact-thanks.php file it calls for at the end).
So many $Body , How About :
$Body = " Name : $Name \n Company : $Company \n Deadline : $Deadline \n Interested : $Interested \n Message : $Message";
Is This What You Looking For ?

Why wont messages go through my contact form to my email? [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I'm trying to have a contact form on my page. Nothing crazy, just a simple form. I've tried multiple contact forms from the web, and they all look fine, they all work fine when filling it out on my site and even when you hit submit it brings you to the PHP page fine and everything, but I never get the message in my email. I've checked my spam and everything and I'm just not getting the message.
Here's the form html:
<form method="post" action="sendit.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Phone">Phone:</label>
<input type="text" name="Phone:" id="Phone" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label>
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
Here's the PHP:
<?php
$EmailFrom = "mjd8079#yahoo.com";
$EmailTo = "mjd8079#yahoo.com";
$Subject = "Contact";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=sendit.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
This is the piece of the code which will help you to send the email as well as, it would ensure approx 80% that the mail will deliver in Inbox and not in Spam
require_once "Mail.php";
require_once('Mail/mime.php');
$to = "mjd8079#yahoo.com";
$subject = "Contact";
$header = "from: Some Name <mjd8079#yahoo.com> \r"."<br >";
$header .= "Content-Type: text/html; charset=ISO-8859-1 \r"."<br >";
$header .= "Return-Path: <mjd8079#yahoo.com> \r"."<br >";
$header .= "X-Priority: 1 (Highest) \r"."<br >";
$header .= "X-MSMail-Priority: High \r"."<br >";
$header .= "Importance: High \r"."<br >";
$header .= "MIME-Version: 1.0 \r"."<br >";
$htmlbody = "<html>
<table width='430' border='1' cellpadding='5' cellspacing='5' class='bg1' style='border-collapse:collapse;'>
<tr>
<td width='185' bgcolor='#003366'><font color='#ffffff' face='Verdana'>Your Name:</font></td>
<td width='210' valign='middle' bgcolor='#FFFFCC'><font color='#000000' face='Verdana' style='font-weight:bold'>$name</font></td>
</tr>
<tr>
<td bgcolor='#003366'><font color='#ffffff' face='Verdana'>E mail</font></td>
<td bgcolor='#FFFFCC'><font color='#000000' face='Verdana' style='font-weight:bold'>$Email</font></td>
</tr>
<tr>
<td bgcolor='#003366'><font color='#ffffff' face='Verdana'>Telephone Number</font></td>
<td bgcolor='#FFFFCC'><font color='#000000' face='Verdana' style='font-weight:bold'>$Tel</font></td>
</tr>
<tr>
<td bgcolor='#003366'><font color='#ffffff' face='Verdana'>Message</font></td>
<td bgcolor='#FFFFCC'><font color='#000000' face='Verdana' style='font-weight:bold'>$Message</font></td>
</tr>
</table>
</html>";
$from = "Some Name <mjd8079#yahoo.com>";
$host = "smtp.yahoo.com";
$port = "587";
$username1 = "mjd8079#yahoo.com";
$password1 = "yourpassword";
$crlf = chr(10);
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setHTMLBody($htmlbody);
$body = $mime->getMessageBody();
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username1,
'password' => $password1)
);
$mail = $smtp->send($to, $headers, $body );
There may be no issues with your code you may need to confirm that the server running PHP has an smtp server setup on it and that PHP knows about it.
You will have to check in you php.ini file to see in a server has been setup, the setting can be seen hear http://php.net/manual/en/mail.configuration.php.
if you also have access to the commandline on the server you can test that the server has access to send emails by doing the command
/usr/sbin/sendmail -t -i mjd8079#yahoo.com
This is a test
ctrl-d
if you don't get a message then it is most like the server not the code
tho in my experience Yahoo can be a bit grumpy on sending to may email, and can start blocking email if there is to many in a short period of time, so try another email address

Contact form submit error

I've got a simple contact form set up, but am having a little trouble with the finishing touches. I'm getting an error message whenever the form is submitted. Was hoping someone can take a look at my code and point out my mistake. Thanks!
(edited) Forgot to mention the error is that once form is submitted, I am being redirected to the error page (error.html) instead of the success (contactthanks.php) page.
HTML:
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="City">City:</label>
<input type="text" name="City" id="City" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
PHP:
<?php
$EmailFrom = "";
$EmailTo = "MYEMAIL#gmail.com";
$Subject = "";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
exit;
}
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
It is redirecting to your error page because the call to mail is returning false (indicating the email was not accepted for delivery) and that is exactly what you are telling it to do in that situation.
You need to check the SMTP set up on your server.
Typically the settings to check for are sendmail_from and sendmail_path in your PHP.ini file. Seeing as you are already setting a From header, sendmail_path is likely to not be set up correctly.
See what's causing the problem with
ini_set("display_errors", "1");
error_reporting(E_ALL);`.
My guess is you have wrong smtp settings and mail function fails.

php to form script? syntax error unexpected

Hi Can anyone suggest a quick form script for a php form?
I generated the one below from telepro and modified the html and emails a bit, but I get this error for the checkbox
Parse error: syntax error, unexpected '=' in /home/inn.co.uk/public/mailer.php on line 14
thanks for your help
Regards
Judi
<form method="POST" action="contact.php">
<div class="form-field">
<input type="text" name="Name" onFocus="if(this.value=='Name')this.value='';" value="Name">
</div>
<div class="form-field">
<input type="text" name="Telephone" onFocus="if(this.value=='Telephone')this.value='';" value="Telephone">
</div>
<div class="form-field">
<input type="text" name="Timetocall" onFocus="if(this.value=='Time to call')this.value='';" value="Time to call">
</div>
<div class="form-field">
<ul class="tickboxes">
<li>Do you agree to our<br/>Terms of Business <input type="checkbox" name="DoyouagreetoourTermsofBusiness?" value="Yes" /></li></ul></div>
<div class="button">
<input type="image" src="images/submit.jpg" value="" name="submit">
</div>
</form>
<?php
// Website Contact Form Generator
// http://www.tele-pro.co.uk/scripts/contact_form/
// This script is free to use as long as you
// retain the credit link
// get posted data into local variables
$EmailFrom = "enquiry#inn.co.uk";
$EmailTo = "judith#yahoo.co.uk";
$Subject = "New enquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Telephone = Trim(stripslashes($_POST['Telephone']));
$Timetocall = Trim(stripslashes($_POST['Timetocall']));
$DoyouagreetoourTermsofBusiness? = Trim(stripslashes($_POST['DoyouagreetoourTermsofBusiness?']));
// validation
$validationOK=true;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Telephone)=="") $validationOK=false;
if (Trim($Timetocall)=="") $validationOK=false;
if (Trim($DoyouagreetoourTermsofBusiness?)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Timetocall: ";
$Body .= $Timetocall;
$Body .= "\n";
$Body .= "DoyouagreetoourTermsofBusiness?: ";
$Body .= $DoyouagreetoourTermsofBusiness?;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
You are using a question mark in your variable name. That doesn't work.
See the PHP Manual on variables for naming conventions.
replace
$DoyouagreetoourTermsofBusiness?
by
$DoyouagreetoourTermsofBusiness
and it will work fine.

Categories