I'm extremely new to php, roughly 2 days experience.
My conundrum is this:
My html is:
<div class="form">
<form action="php/sendmail.php" method="post" id="contactwidget">
<div class="inp_r"><input type="text" name="wname" id="wname" value="Name" size="22" tabindex="11" alt="Name" /></div>
</div>
<div class="inp_r"><input type="text" name="wemail" id="wemail" value="Email" size="22" tabindex="12" alt="Email" /></div>
</div>
<table>
<tr>
<td class="text_m"><textarea name="wmessage" id="wmessage" cols="28" rows="6" tabindex="13" title="Quick Message">Quick Message</textarea></td>
<td class="text_r"></td>
</tr>
</table>
<div class="loading"></div>
<div><input type="hidden" name="wcontactemail" id="wcontactemail" value="info#joshuas.com" /></div>
<div><input type="hidden" name="wcontacturl" id="wcontacturl" value="php/sendmail.php" /></div>
<div><span>Send</span></div>
</form>
</div>
My php is this:
<?php
$email = $_POST['Email'] ;
$name = $_POST['Name'] ;
$message = $_POST['wmessage'] ;
$headers .= 'From: ' . $from . "\r\n";
mail( "info#gmail.com", "Message from Joshua",
$message, "From: $email" );
?>
All that is returning is an email with "Message from Joshua"
Any ideas??
you have to redirect the page in php script.
header( "location=wherever.php" );
IF you want to test the output use this: http://papercut.codeplex.com/
Related
I've made a custom contact form with PHP working with HTML but I am getting some blank fields when sending an email.
Actually, I have made a table of 4 including Name, Email, Subject, and Message but the fields including Subject & Message are being sent empty.
I would appreciate any help given.
Thank you.
Html Code:
<form action="mail.php" method="post">
<div class="form-block clearfix">
<input type="text" placeholder="name*" id="name" />
<input type="text" placeholder="email*" id="email" />
</div>
<div class="form-block clearfix">
<input type="text" placeholder="subject*" id="sub" />
</div>
<div class="form-block">
<textarea cols="1" rows="1" placeholder="Message*" id="message" ></textarea>
</div>
<div class="submit-btn">
<input type="button" id="submit" value="submit" class="detail-submit"/>
</div>
</form>
PHP:
<?php
$to = "My email";
$from = "";
$cc = "";
$subject = "Contact us form";
$errmasg = "";
$name = htmlentities(trim($_POST['name']));
$email = htmlentities(trim($_POST['email']));
$sub = htmlentities(trim($_POST['sub']));
$message = htmlentities(trim(nl2br($_POST['message'])));
if($email){
$message = "<table border='0' cellpadding='2' cellspacing='2' width='600'>
<tr><td>Name: ".$name." </td></tr>
<tr><td>Email: ".$email."</td></tr>
<tr><td>Subject: ".$sub."</td></tr>
<tr><td>Message:".$message."</td></tr>
</table>";
}else{
$errmasg = "No Data";
}
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From:'.$from . "\r\n";
$headers .= 'Cc:'.$cc . "\r\n";
if($errmasg == ""){
if(mail($to,$subject,$message,$headers)){
echo 1;
}else{
echo 'Error occurred while sending email';
}
}else{
echo $errmasg;
}
?>
You need to add an element NAME in the subject and message field.
Just replace your form code to below code:
<form action="mail.php" method="post">
<div class="form-block clearfix">
<input type="text" placeholder="name*" id="name" />
<input type="text" placeholder="email*" id="email" />
</div>
<div class="form-block clearfix">
<input type="text" name="sub" placeholder="subject*" id="sub" />
</div>
<div class="form-block">
<textarea cols="1" rows="1" name="message" placeholder="Message*" id="message" ></textarea>
</div>
<div class="submit-btn">
<input type="button" id="submit" value="submit" class="detail-submit"/>
</div>
</form>
Each form element that you wish to appear in the POST array data when the form is submitted ( and thus to be available using $_POST['fieldname'] ) needs a name attribute. The ID attribute is optional but of limited use in many situations - certainly not required in a traditional form submission such as this..
The input button submit will NOT submit the form unless you do so with Javascript. It might be better to use a submit button as below.
<form action="mail.php" method="post">
<div class="form-block clearfix">
<input type="text" placeholder="name*" name="name" />
<input type="text" placeholder="email*" name="email" />
</div>
<div class="form-block clearfix">
<input type="text" placeholder="subject*" name="sub" />
</div>
<div class="form-block">
<textarea cols="100" rows="1" placeholder="Message*" name="message" ></textarea>
</div>
<div class="submit-btn">
<input type="submit" name="submit" value="Submit" class="detail-submit"/>
</div>
</form>
Not sure why you are having issues ~ perhaps the following will offer enlightenment. It is tested to the point of failing to send an email ( no local mailserver on dev machine at present ) and is an "all in one page" demo where the PHP emulates the original form action mail.php
<?php
/* this emulates mail.php */
error_reporting( E_ALL );
/* use a session variable */
session_start();
/* for testing single page demo */
$singlepage=true;
if( $_SERVER['REQUEST_METHOD']=='POST' ){
$to = "My email";
$from = $cc = '';
$subject = "Contact us form";
$errmasg = '';
/* filter POST data */
$args=array(
'name' => FILTER_SANITIZE_STRING,
'email' => FILTER_SANITIZE_EMAIL,
'sub' => FILTER_SANITIZE_STRING,
'message' => FILTER_SANITIZE_STRING
);
$_POST=filter_input_array( INPUT_POST, $args );
/* assign as variables */
extract( $_POST );
$name = htmlentities(trim($name));
$email = htmlentities(trim($email));
$sub = htmlentities(trim($sub));
$message = htmlentities(trim(nl2br($message)));
if( $email ){
$message = "<table border='0' cellpadding='2' cellspacing='2' width='600'>
<tr><td>Name: ".$name." </td></tr>
<tr><td>Email: ".$email."</td></tr>
<tr><td>Subject: ".$sub."</td></tr>
<tr><td>Message:".$message."</td></tr>
</table>";
}
# REMOVE THIS LINE or COMMENT IT OUT FOR REAL USAGE
#exit( sprintf("<pre>%s\n%s</pre>",$message, print_r( $_POST,true ) ) );
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From:'.$from . "\r\n";
$headers .= 'Cc:'.$cc . "\r\n";
if($errmasg == ""){
if( mail( $to, $subject, $message, $headers ) ){
$_SESSION['mailsent']=1;
}else{
$_SESSION['mailsent']=2;
}
}else{
$_SESSION['mailsent']=3;
}
/*
If you are using mail.php then use a `header` to redirect the user
back to the contact page - assumed to be called `contact.php`
*/
if( !$singlepage ) header( 'Location: contact.php' );
}
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>POST to email</title>
</head>
<body>
<!-- removed attribute action as this works on same page here -->
<form method="post">
<?php
if( !empty( $_SESSION['mailsent'] ) ){
switch( $_SESSION['mailsent'] ){
case 1:$message='Your message was sent successfully';break;
case 2:$message='Sorry - we had a problem sending your email';break;
case 3:$message='Bogus - no data';break;
}
printf( '<h1>%s</h1>', $message );
unset( $_SESSION['mailsent'] );
}
?>
<div class="form-block clearfix">
<input type="text" placeholder="name*" name="name" /><!-- element has a NAME -->
<input type="text" placeholder="email*" name="email" />
</div>
<div class="form-block clearfix">
<input type="text" placeholder="subject*" name="sub" />
</div>
<div class="form-block">
<textarea cols="100" rows="1" placeholder="Message*" name="message" ></textarea>
</div>
<div class="submit-btn">
<input type="submit" class="detail-submit" /><!-- a SUBMIT button -->
</div>
</form>
</body>
</html>
Typical output for debugging
Array
(
[name] => fred flintstone
[email] => fred#bedrock.com
[sub] => betty had better bake a cake
[message] => hey betty
)
I'm having an issue passing $_SESSION variables through a multiple page form process using PHP mail. The emails are coming through fine, although they not displaying the variables.
My goal is to have users fill out forms on multiple pages, and have the data emailed back to me.
Page 1
<?php
session_start();
?>
<form method="post" action="submitpage.php">
<label>
<input type="radio" name="vehicle_type" value="car" checked />
<img class="img-responsive" src="img/vehicle2.png">
</label>
<label>
<input type="radio" name="vehicle_type" value="suv" />
<img class="img-responsive" src="img/vehicle2.png">
</label>
<label>
<input type="radio" name="vehicle_type" value="van" />
<img class="img-responsive" src="img/vehicle2.png">
</label>
<label>
<input type="radio" name="vehicle_type" value="truck" />
<img class="img-responsive" src="img/vehicle2.png">
</label>
<label>
<input type="radio" name="vehicle_type" value="none" />
<img class="img-responsive" src="img/vehicle2.png">
</label>
</form>
Page 2
<?php
session_start();
$_SESSION['vehicle_type'] = $_POST['vehicle_type'];
?>
<form method="post" action="emailexample.php" id="submit-form">
<input type="Email" name="email">
<input type="submit" name="submit" value="Submit" id="submitbtn">
</form>
Page 3
<?php
session_start();
$to = 'myemail#gmail.com';
$subject = 'test ';
$message = "Your Vehicle Type is: " . $_POST['vehicle_type'] ."\r\n";
$headers = 'From: email#example.com' . "\r\n" .
mail($to, $subject, $message, $headers);
?>
On page 1 you should put submit button something like this
<input type="submit" name="submit" value="Submit" />
On page 3 you should change
$message = "Your Vehicle Type is: " . $_SESSION['vehicle_type'] ."\r\n";
and you're missing semicolon in $headers variable at the end. It should be
$headers = 'From: email#example.com' . "\r\n";
In page 3
use $_SESSION['vehicle_type'] instead of $_POST['vehicle_type']
I was working with an HTML contact form, its action is a mail sending php script. But it is not working when i am clicking on the send button. I couldn't find any possible here. Please someone help me to fix this.
HTML form
<div class="contact-form">
<form action="sendmail.php" method="post">
<div class="control-group"><label class="nameLabel" for="name">Name</label> <input id="name" name="name" type="text" /></div>
<div class="control-group"><label class="emailLabel" for="email">Email</label> <input id="email" name="email" type="text" /></div>
<div class="control-group"><label class="messageLabel" for="message">Message</label><textarea id="message" name="message"></textarea></div>
<div class="control-group"><button type="submit">Send</button></div>
</form>
<h1 class="status-message-contact"></h1>
</div>
PHP code
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
$to="sarath.sarigama#gmail.com";
$subject="WEB Enquiry!";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$email_from."\r\n";
$message="
Name:
$name
<br>
Email-Id:
$email
<br>
Message:
$query
";
if(mail($to,$subject,$message,$headers))
header("Location:../index.php?msg=Successful Submission! Thankyou for contacting us.");
else
header("Location:../index.php?msg=Error To send Email !");
//contact:-your-email#your-domain.com
}
?>
you dont have submit button name ,change name of the button
<button name='submit' type="submit">Send</button>
or use input tag
<input name='submit' type='submit'>
Replace
<button type="submit">Send</button>
with
<input type="submit" value="Send" />
And maybe add
<input type="hidden" name="submit" value="1" />
For the isset( $_POST['submit'] )
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
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.