I'm new to WordPress. I create a static page contact.php. In contact page, I have a contact form, so users would get in touch with me. When the user would click the submit button it should go to index.php and prompting the success of email delivery otherwise display not successful..
this is the code of contact.php
<form class="form" method="post" action="/send-email.php">
<p class="name">
<input type="text" name="name" id="name" placeholder="Enter your name" size="40" />
<label for="name">Name</label>
</p>
<p class="email">
<input type="text" name="email" id="email" placeholder="mail#example.com" size="40" />
<label for="email">Email</label>
</p>
<p class="web">
<input type="text" name="telephone" id="telephone" placeholder="000-000-000" size="40" />
<label for="telephone">Telephone</label>
</p>
<p class="text">
<label for="message">Message</label>
<textarea name="message" placeholder="Write something to us" cols="40" rows="5" /></textarea>
</p>
<p class="submit">
<input type="submit" value="Send" />
<input type="reset" value="Cancel" />
</p>
</form>
send-email.php
<?php
$ToEmail = 'sample#sample.com';
$EmailSubject = 'Contact Form';
$mailheader = "From: " . $_POST["email"] . "\r\n";
$mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = " <strong>Name:</strong> " . $_POST["name"] . "";
$MESSAGE_BODY .= "<br> <strong>Email:</strong> " . $_POST["email"] . "";
$MESSAGE_BODY .= "<br> <strong>Telephone:</strong> " . $_POST["telephone"] . "";
$MESSAGE_BODY .= "<br><br> <strong>Message:</strong> " . nl2br($_POST["message"]) . "";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
/* echo "<pre>";
print_r($MESSAGE_BODY);
echo "<pre>"; */
header("Location: /index");
But it's not sending. And the URL looks just like www.site.com/send-email.php
What am I missing in here? Any ideas? I would really appreciate your help. Thanks.
Sounds like die("Failure") might be kicking in and logging the "Failure" message instead of printing it on screen. Or the mail module isn't installed, so it is running into an error where it doesn't know what the mail() function even is—admittedly unlikely. Not too sure.
My guess is that your server is not even set up to send mail properly yet. That can be a complicated setup if you are running your own server. If you are on a shared server, it really should be set up already... unless your host is not very good.
In any case, if you are running in WordPress I'd recommend installing the Jetpack plugin by the folks who made WordPress itself. It includes a feature that adds a contact form to a page with a few clicks of your cursor.
If that form won't send an email, there is something wrong that is beyond the scope of the information you provided in your question.
<form class="form" method="post" action="index.php">
<p class="name">
<label for="name">Name</label>
<input type="text" name="name" id="name" placeholder="Enter your name" size="40" />
</p>
<p class="email">
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="mail#example.com" size="40" />
</p>
<p class="web">
<label for="telephone">Telephone</label>
<input type="text" name="telephone" id="telephone" placeholder="000-000-000" size="40" />
</p>
<p class="text">
<label for="message">Message</label>
<textarea name="message" placeholder="Write something to us" cols="40" rows="5" /></textarea>
</p>
<p class="submit">
<input type="submit" name="submit" value="Send" />
<input type="reset" value="Cancel" />
</p>
</form>
AND YOUR index.php
<?php
if(isset($_POST['submit'] == 'Send')) {
$ToEmail = 'sample#sample.com';
$EmailSubject = 'Contact Form';
$mailheader = "From: " . $_POST["email"] . "\r\n";
$mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = " <strong>Name:</strong> " . $_POST["name"] . "";
$MESSAGE_BODY .= "<br> <strong>Email:</strong> " . $_POST["email"] . "";
$MESSAGE_BODY .= "<br> <strong>Telephone:</strong> " . $_POST["telephone"] . "";
$MESSAGE_BODY .= "<br><br> <strong>Message:</strong> " . nl2br($_POST["message"]) . "";
$status = mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
}
if($status){
echo "your success message";
}
?>
try this
ONE MORE THING
Since you are using this on wordpress you should better use wp_mail funciton of wordpress
Related
I am using following script to send contact us form details through email from my website.
But script is not working, getting Error sending mail message.
Not getting what is the problem here:
<?php
$MailToAddress = "ToEmailID";
$redirectURL = "index.html";
$MailSubject = "Inquiries - Contact Us";
$redirectURL = "index.html";
$message_body = "NAME: ".$_POST["name"]."\r\n";
$message_body .= "E-Mail: ".$_POST["email"]."\r\n";
$message_body .= "SUBJECT: ".$_POST["subject"]."\r\n";
$message_body .= "MESSAGE: ".$_POST["message"]."\r\n";
if (!mail($MailToAddress, $MailSubject, $message_body)) {
echo "Error sending e-mail!";
}
else {
header("Location: ".$redirectURL);
}
?>
And here is the form:
<form action="submit.php" class="contact-form" method="post">
<div class="col-md-4"><input id="senderName" name="name" placeholder="name" type="text" /></div>
<input id="senderEmail" name="email" placeholder="email address" type="text" />
<input id="subject" name="subject" placeholder="subject" type="text" />
<textarea id="message" name="message" placeholder="Message" required="" rows="6"></textarea>
<input class="btn-regular alignleft contact_button" type="submit" value="SUBMIT" name="submit">
</form>
I am receiving blank emails from my website every day at 8:15am - 8:19am.
They don't contain any information in them and do not contain the input id's either.
I have gone through multiple forums about this but I am new to PHP and seams to be a bit over my head.
<?php
function sendFormByEMail($msgBody) {
$to = "email#gmail.com";
$subject = "web visitor";
$from = "email#gmail.com";
$mailHdr = "";
$mailHdr .= "From: ".$from."\r\n";
$mailHdr .= "Reply-To: ".$from."\r\n";
return mail($to, $subject, $msgBody, $mailHdr);
}
function getMessageText() {
$msgTxt = "";
$msgTxt .= "Sent: " . date("Y/m/d H:i:s") . "\n";
foreach ($_POST as $key => $value)
{
//$msgTxt .= urlencode($key) . "=" . urlencode($value) . "\n";
$msgTxt .= $key . " = " . $value . "\n";
}
return $msgTxt;
}
if (sendFormByEMail(getMessageText())) {
$nextPage = '../index2.html';
} else {
$nextPage = '../index2.html';
}
header("Location: $nextPage");
?>
HTML
<form action="php/formsProcessor.php" method="post" enctype="multipart/form-data" name="quote" id="quote">
<div class="row">
<label for="name">Your name:</label><br />
<input id="name" class="input" name="name" type="text" value="" size="30" /><br />
</div>
<div class="row">
<label for="email">Your email:</label><br />
<input id="email" class="input" name="email" type="text" value="" size="30" /><br />
</div>
<div class="row">
<label for="message">Your message:</label><br />
<textarea id="message" class="input" name="message" rows="7" cols="30"></textarea><br />
</div>
<input id="submit_button" type="submit" value="Send email" />
</form>
I have been trying to fix this for a few weeks now and any help would be GREATLY appreciated.
Add this text to the header:
"Content-type: text/html charset=iso-8859-1 \r\n"
I'm by no means a web designer/coder, but I have enough general knowledge to get my website going. Just a simple portfolio website.
I'm having some problems with my contact form though. It's strictly CSS, HTML and PHP but when I put in the information (name, email and message) to test it, it sends me an email with those field headings, but no content. For example, the email displays as;
Name:
Email:
Message:
Even when filled out with information.
I have a feeling it's something small and a stupid error, so any help is greatly appreciated!
HTML
<div id="contact-area">
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</form>
</div>
<div id="contact-area2">
<form method="post" action="contactengine.php">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
</form>
<div id="submit-button">
<form method="post" action="contactengine.php">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
</div>
</div>
PHP
<?php
$EmailFrom = "contact#brettlair.ca";
$EmailTo = "contact#brettlair.ca";
$Subject = "Contact Form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.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=index.htm\">";
}
?>
You have your form fields in one form, and the submit button in another. They need to be in the same form.
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</div>
<div id="contact-area2">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
<div id="submit-button">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
$Name = Trim(stripslashes($_POST['Name']));
There is no Trim function, should be trim (lowercase).
I'm not receiving mails on the email mail#example.com. Below is my form code and my send-mail.php code. Can anyone help me with this cause everything seems working great bu i'm not receiving any emails. I'm using localhost as the server.
Contact form:
<form id="contactForm" action="#" method="post">
<p>Email us by filling in the form below. Make sure you fill in the message and all fields.</p>
<fieldset>
<div>
<input name="name" id="name" type="text" class="form-poshytip" title="Enter your name" />
<label>Name</label>
</div>
<div>
<input name="web" id="web" type="text" class="form-poshytip" title="Enter your surname" />
<label>Surname</label>
</div>
<div>
<input name="email" id="email" type="text" class="form-poshytip" title="Enter your email address" />
<label>Email</label>
</div>
<div>
<textarea name="comments" id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea>
</div>
<!-- send mail configuration -->
<input type="hidden" value="mail#example.com" name="to" id="to" />
<input type="hidden" value="Enter the subject here" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p><input type="button" value="Send" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</fieldset>
</form>
<p id="sent-form-msg" class="success">Form data sent. Thanks for your feedback.</p>
<!-- ENDS form -->
and here is the send-mail.php
<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['mail#example.com'];
//data
$msg = "NAME: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}
?>
$_POST['subject'];
$_POST['to'];
$_POST['myemail#gmail.com'];
$_POST['name'];
$_POST['email'];
$_POST['web'];
$_POST['comments'];
I didn’t find any of these elements in your form. That's the reason why nothing is happening.Try
echo '<pre>';
print_r($_POST);
This will give you the posted array when the form is submitted.
i have some suggestion.if u have kept the 'to' address as hidden in the form then why cant u try keeping it directly in sendmail function and in $from you try to keep
<?php
$to="kurtfarrugia92#gmail.com";
$from =$_POST['field_name'];
// not the mail id because i didn't see any field with name as "kurtfarrugia92#gmail.com"
?>
You cannot use this function to send mail from localhost. I am not sure but you should try PHP mailer for this task.
After researching several questions and try multiple options, I couldn't make it work still!
I have this contact form that won't be sent.
<form id="contact" method="post" action="process.php">
<fieldset>
<label for="name">Name:</label>
<input type="text" name="name" placeholder="Your name" title="Your name" class="required">
<label for="email">E-mail:</label>
<input type="email" name="email" placeholder="yourmail#domain.com" title="Your e-mail address" class="required email">
<label for="phone">Phone number:</label>
<input type="tel" name="phone" placeholder="+34 111 22 33 44" title="Your phone number">
<p> </p>
<input type="radio" name="rsvp" value="si">
<span class="destacar-contacto">ACCEPT</span> the invitation<br>
<input type="radio" name="rsvp" value="no">
<span class="destacar-contacto">REJECT</span> the invitation<br>
<p> </p>
<p class="negrita-contacto">If you're coming: what would you like better?</p>
<input type="radio" name="menu" value="carne"> Calf sirloin with foie<br>
<input type="radio" name="menu" value="pescado"> Marinade salmon with dill<br>
<input type="radio" name="menu" value="vegetariano"> Fungus risotto<br>
<label for="mas">Is someone coming with you? Let us know their name and their prefered menu here:</label>
<textarea name="mas"></textarea>
<label for="message">Aditional message:</label>
<textarea name="message"></textarea>
<input type="submit" name="submit" class="boton" id="submit" value="Enviar" />
</fieldset>
</form>
And this is the PHP function:
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$rsvp = strip_tags($_POST['rsvp']);
$menu = strip_tags($_POST['menu']);
$mas = strip_tags($_POST['mas']);
$message = strip_tags($_POST['message']);
mail( "formulario#ourdreamjourney.com", "rsvp",
"Name: $name\nEmail: $email\nPhone: $phone\nRsvp: $rsvp\nMenu: $menu\nMas: $mas\nMessage: $message\n",
"From: Our Dream Journey <mail#hotmail.com>" );
I tried randomly to send just "Name: $name" and I got an e-mail! But then put all the other options back and nothing again...
Someone can help me please?
Thank you so much in advance! :)
You can use phpMailer class. Download this library from here. Many example with to send email.
http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list
Edit:
Try this code
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From:Our Dream Journey <mail#hotmail.com>' . "\r\n";
if(mail( "formulario#ourdreamjourney.com", "rsvp",nl2br("Name: $name\nEmail: $email\nPhone: $phone\nRsvp: $rsvp\nMenu: $menu\nMas: $mas\nMessage: $message\n"),
$headers )) echo "Sent"; die;
Try to add all the information to the header element:
$headers = "From: myplace#here.com\r\n";
$headers .= "Reply-To: myplace2#here.com\r\n";
$headers .= "Return-Path: myplace#here.com\r\n";
$headers .= "CC: sombodyelse#noplace.com\r\n";
$headers .= "BCC: hidden#special.com\r\n";
Maybe there also other options that I don't remember like MIME
Maybe another problem is that some of the variables break the string(close the string). Try to print it somewhere,a file with file_put_contents or just echo it