Html php email form not working - php

Hello I am trying to add a html email form to my website but cannot get it to work. The following is the code I currently have but when I try the form I don't receive an email.
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("****************", $subject, $message, $from);
echo "Email sent!";
}
}
?>

I recommend using PHPMailer.
It will save you a lot of trouble and there are plenty of guides, with freely available default configs where all you need to do is modify the contents, sender and recipient of the email.

first - use $_POST, not $_REQUEST;
second - is there right settings on your server? maybe there is no mail support;
and the last - 4th argument of mail function is not "from", it's headers where you can also set mime-type and others..
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

the error is in this line :
mail("****************", $subject, $message, $from);
replace the asterisks with your email

mail function returns boolean, check whether it is sending or not sending.
Change your mail code like below and try to know whats happening.
`
if (mail("himmerz#gmail.com", $subject, $message, $from)) {
echo 'send';
} else {
echo 'not send';
}
`

mail("****************", $subject, $message, $from);
change to:
mail($email, $subject, $message, $from);

Related

PHP Contact Form Not Sending All Data

I took the code below from a website but it only seems to send the Message and not the Name or Email. Can anyone tell me why?
<?php $action=$_REQUEST['action'];
if ($action=="") { ?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else {
$message=$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: dG<my#email.com>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("my#email.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
I thought that I could change
mail("my#email.com", $subject, $message, $from);
to be more like
mail("my#email.com", $subject, $name, $email, $message, $from);
but that didn't work.
As you can see, I don't know much about PHP, so please keep it as simple as you can.
Thanks.
The mail() function accepts these arguments:
to, subject, message, headers, parameters
So, to include the contents of the $name and $email variables in the message, you'll probably want to add them to the message variable. Something like:
$message = $name . $email . $message;
Then, when you send the e-mail with:
mail("my#email.com", $subject, $message, $from);
the $message will include the $name and $email contents.
Once you get that working, you'll probably want to add some space between the name, email and message.
Here is what the complete else block could look like:
else{
$from="From: dG<my#email.com>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
$message = $name . $email . $message;
mail("my#email.com", $subject, $message, $from);
echo "Email sent!";
}
Here is a link to the full documentation on the mail() function:
http://php.net/manual/en/function.mail.php

PHP Form doesn't work

My contact form doesn't work. Emails are not being sent.
Webpage Code :
<!--Form Start-->
<form method="post" action="sendmail.php">
Email: <input name="email" type="text"><br>
Message:<br>
<textarea name="message" rows="15" cols="40"></textarea><br>
<input type="submit">
</form>
<!--Form End-->
PHP Script :
<?php
$to = "oxydyzestudios#gmail.com";
$subject = "Comment";
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers);
if($sent) {
print "Your mail was sent successfully";
} else {
print "We encountered an error sending your mail";
}
?>
Yes, the email is correct.
Live Demo : http://unitedasone.web1337.net/form.html
Any help would be appreciated.
There's nothing wrong with your code and it reports success.
This is likely a problem with your mail set up on your server, if you're seeing Your mail was sent successfully then php's mail function has successfully passed the mail to the server for delivery.
From php.net:
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
How is mail sent on your server?

php contact form not working with some email addresses?

I have a really simple php contact form on one of my sites, the problem is that it won't work when sending emails to some addresses.
It works fine sending to my gmail address, but it doesn't work with iCloud (#me.com) addresses or other domain specific emails that I have set up.
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("myemailaddress#me.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
If it didn't work at all I'd know there was a syntax error, but I get the 'Email Sent!' confirmation.
add if statement to the mail function :
if( mail("myemailaddress#me.com", $subject, $message, $from)) echo "Email sent!";
else echo "failed" ;
this way you'll know if it was sent or not .
then start checking the problem .
you man check your php.ini file :
check
sendmail_from = '';
sendmail_path = '';
and fill them with needed data ... maybe some address doesnt accept emails with no full data in the header . maybe they found it as a spam or somthing else .
Just have a look at your else part where you are using mail .Just below that is the echo so it always get executed as soon as it enters the else block.So, check for mail by if & else condition and then show the massage accordingly

Form for sending mail not sending

I have a "tell a friend" pop up email form that allows users to share my page with an email address that they enter. It pops up fine, but I can't get the form to send the email.
html:
<div id="tellfriend">
Close
<form id='tellafriend_form' method="post" action="#sendMessage" name="tellafriend_form">
<label for="name">Your Name:</label>
<input type="text" id="name" name="name" />
<label for="to">Friend's email:</label>
<input type="text" id="to" name="to" />
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" />
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea>
<input type="submit" name="submit" value="Submit">
</form>
</div><!-- #tellfriend -->
javascript that handles the "pop up":
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script>
$(function() {
$('#tellfriend').hide();
$('#sendMessage').click(function(e) {
$("#tellfriend").fadeToggle('fast');
});
});
</script>
php that's supposed to send the mail:
<?
if (isset($_POST['Submit'])) {
// This will check to see if the form has been submitted
$senders_name = $_POST['name'];
// The person who is submitting the form
$recipient_friend = $_POST['to'];
// The forms recipient
$subject = $_POST['subject'];
// The subject line
$message = $_POST['message'];
// The message being sent
mail($recipient_friend, "From $senders_name", $subject, $message);
if (isset($_POST['your_email'])) {
echo "<br>Your friend has been contacted <br><br>Thank you $senders_name";
}}
?>
Disclaimer: PHP newbie, hoping to learn. Thanks!
The order of your parameters in mail function is not correct. see this
it should be
mail($recipient_friend, $subject, $message);
if you want to use headers then do this
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$recipient_friend.' <'.$recipient_friend.'>' . "\r\n";
$headers .= 'From: '.$sender.' <'.$senderEM.'>' . "\r\n";
Then call mail like this
mail($recipient_friend, $subject, $message, $headers);
You have one error in your PHP code:
if (isset($_POST['Submit'])) {
should be:
if (isset($_POST['submit'])) {
with a lowercase "s".
Indeed the name of you submit button is "submit" but the value is "Submit".
You could eventually do that:
if (isset($_POST['submit']) && $_POST['submit'] == 'Submit') {
And your mail parameters are not correct like boug said.
You have 2 errors
first:
if (isset($_POST['submit']))
// $_POST is case sensitive
second:
if (isset($_POST['your_email']))
// you dont have an inout named 'your_email'

PHP contact form not sending

I have a contact form on a page that sends the details of the form to an email address. You can view it here, www.wonder.ie
The HTML for the form is the following:
<form id="form" name="form27" class="wufoo page" enctype="multipart/form-data" method="post" action="mailer.php">
<ul>
<li id="foli1">
<label class="op" id="title1" for="Field1">Name</label>
<div><input id="Field1" name="name" type="text" class="op required" value="" maxlength="255" tabindex="1" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>
</li>
<li id="foli2">
<label class="op" id="title2" for="Field2">Email</label>
<div><input id="Field2" name="email" type="text" class="op required email" value="" maxlength="255" tabindex="2" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>
</li>
<li id="foli3">
<label class="op" id="title3" for="Field3">Inquiry</label>
<div><textarea id="Field3" name="message" class="op required" rows="10" cols="50" tabindex="3" onkeyup="handleInput(this);" onchange="handleInput(this);"></textarea></div>
</li>
</ul>
<input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />
</form>
And for my PHP it is this:
<?php
if(isset($_POST['submit'])) {
$to = "AN_EMAIL#ADDRESS.COM";
$subject = "Email from Wonder.ie";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
Does everything look correct? I know I have the form names matched correctly with the PHP but I can't figure out why I'm not receiving the email you know - FYI the PHP on the site has a real email address, not AN_EMAIL#ADDRESS.COM. Once I hit the submit button I am taken to mailer.php but I notice the echo "blarg!" so my guess is the email is not being sent.
Thank you!
You should change
if(isset($_POST['submit'])) {
to
if(isset($_POST['saveForm'])) {
Try changing
if(isset($_POST['submit'])) {
to
if(isset($_POST['saveForm'])) {
This is because $_POST looks for the name of a form input, not the type.
If nothing above helps, try and see if you can debug the code.
Catching PHP mail() errors and showing reasonable user error message
In your PHP code you check if $_POST['submit'] is set, but in your HTML code you gave the submit button the name of saveForm so you should change the line
if(isset($_POST['submit'])) {
to
if(isset($_POST['saveForm'])) {
Hope this helped you :)
Some email servers won't accept emails without appropriate headers and you haven't provided any. This is what I use.
http://us2.php.net/manual/en/function.mail.php
$header = "From: ".$fromText."\r\n";
$header .= "Cc: ".$ccText."\n";
$header .= "Reply-To : ".$fromText."\r\n";
$header .= "Return-Path : ".$fromText."\r\n";
$header .= "X-Mailer: PHP\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
you are using
if(isset($_POST['submit'])) { but, you have save the submit button name assaveForm So, use if(isset($_POST['saveForm'])) {
your problem is it's pour out blarg.
it's definitely the post does not reach your
code->
mail($to, $subject, $body);
and the name of the submit should be changed to
'saveForm'
by the way :)..
just tried
mail($to, $subject, $body);
in your x.php , upload it and chage to , subject and body to right things
and if it's sent then the mail function works okay.
if(#mail($emailRecipient, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
this is also a good code I have found in stackoverflow
to check if mail function works.
In your html your have
<input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />
but in the php file when you check for $_POST["submit"], which is not right.
You need to change if(isset($_POST['submit'])) to if(isset($_POST['saveForm']))
or if(isset($_POST['submit'])) to if(isset($_POST))
HTML form mail sending guide in PHP http://top-answers.net/webhost/web-hosting.html

Categories