This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I'm trying to setup a contact form on a website I'm working on, the code for which looks like this:
<form action="contact.php" method="POST">
<ul>
<li>
<label for="name">Name:</label><br>
<input type="text" name="name" />
</li>
<br>
<li>
<label for="email">E-mail:</label><br>
<input type="email" name="email" />
</li>
<br>
<li>
<div id="label">Enquiry:</div>
<select name="interest"><br>
<option value="Wedding">Wedding</option>
<option value="Engagement/Couple">Engagement or Couple</option>
<option value="Portrait">Portrait</option>
<option value="Family">Family</option>
<option value="Children">Children</option>
</select>
</li>
<br>
<li>
<label for="message">Message:</label><br>
<textarea name="message" cols="40" rows="6"></textarea>
</li>
<br>
<li>
<button class="submit" type="submit" value="Submit">Submit Form</button>
</li>
</ul>
</form>
Originally I just had the form action as a mailto:myemail#example.com but I would obviously prefer for the user to just submit the form and the email be sent instead of just opening their email application. I'm trying to build a PHP script to do this but am having no luck as yet, probably because this is my first time ever even looking at PHP, let alone trying to write it.
I have looked at many different examples and delved into the PHP manual for help but whatever I write leads to the same result, pressing the submit button on my form and receiving nothing in my inbox. So I started a sort of fault finding process to try and help determine the problem. I would start with really basic PHP scripts and then try and add more to each one and see where it broke.
I started by changing the form action to the php test script as below:
<?php
phpinfo() ;
?>
This worked fine and displayed the php info page as it should. Great so I know that my host supports php and has it installed. This is not the problem then. Second I changed the form action to this code below:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
And again it worked as expected showing the Hello World paragraph. After this I attempted the most basic php mail script I could think of which looked like this:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
mail('myemail#example.com', 'Contact Form', 'This is a test');
?>
</body>
</html>
All this succeeds in doing when I press the submit button on my form is displaying a blank page with the url of my php script in the address bar of my browser and from this I have received no email. Not in my inbox or junk folder, nowhere. As this is such a simple script I have two trains of thought at the min. 1 is that I'm just doing something very basic wrong, which is a high possibility considering my extremely limited knowledge of php. 2 is that something more complicated is going on, maybe php settings of my host are not correct for what I'm attempting to do? I don't know.
I apologise for this question being so long winded, I just wanted to show what I'd done so far in the hope that it will help you guys with any assistance you can give me. Any help with my problem is greatly appreciated, thank you.
One thing to consider is that your email may be getting blocked by your email provider. I have a host with Heart Internet and I've tried sending an email from the website being hosted by Heart to my AoL account and the email does not show up at all. But any emails going to Gmail do. This is because AoL has blocked all emails coming from Heart because of websites producing spam.
I will input some PHP code below which should work:
// Input your desired location instead of email address
$to = 'email address';
$subject = 'Test email';
$message = '<html><body>';
$message .= '<h1>This is an email.</h1>';
$message .= '<p>I hope you like it.</p>';
$message .= '</body></html>';
$headers = 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charset=ISO-8859-1\r\n';
mail($to,$subject,$message,$headers);
Or you are running from localhost.
Or your SMTP settings in your php.ini file aren't configured correctly
My host has blocked mail server for the package I'm on. Something I should've checked but in my frustration I've overlooked it. Thanks for not answering my stupid question with stupid answers guys. Sorry to have made you read all that for nothing really but a fresh head and pair of eyes always works wonders!!
check at the top of the form, there is written <form action="contact.php" method="POST"> that's mean form values are posted to contact.php file where the mail functions is written to send email with form's data. Please show the code of contact.php
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I've done my research on this but can't seem to get it to work.
I'm looking to add a contact form to my website that sends an email directly to me. I've watched videos and used code I've found online but nothing works. I even temporarily disabled my website and uploaded just a blank contact form (code below) and a php file (code below) with my only results being that the echo command at the end of the PHP file DOES show up. The email, though, still does not send.
What am I missing? Thank you!
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Temp</title>
</head>
<body>
<form method="post" action="send.php" name="contact_form">
<p>
<input name="name" type="text" />
</p>
<p>
<input name="email" type="text" />
</p>
<p>
<textarea name="message"></textarea>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
</form>
</body>
</html>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "email#myemail.co";
$subject = "Contact Form Submission";
mail ($to, $subject, $message, "From: " . $name);
echo "Your message has been sent. You can expect to hear from us soon.";
?>
I'm sure this is a duplicate, but I just wanted to mention a couple of things to check.
Does your mail() call return true? I would check that. It's possible that your PHP installation is not set up correctly to send mail. There are countless posts on how to check and configure that, which I would suggest reviewing if you haven't already (here's one, for example).
Depending on where you're hosting this, your host's configurations may restrict any outgoing mail that is not from the domain you're hosting. (I've had this problem myself on shared hosts.) Here you're setting the "from" header as the name of the person submitting the form (which would look something like: "From: John Doe"). This may be a problem either on the sending or receiving end of the email (either side rejecting it because it doesn't come from an email address, or a valid email address, etc). Try setting the "from" value to an email address valid on your host (e.g., "myname#mydomain.com"). Then, just include the person's name and email address in the $message of the email.
Hope that helps.
I have two files, testpage.html and testpage.php in the same folder.
This is testpage.html
<!DOCTYPE HTML>
<html>
<body>
<form action="testpage.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
This is testpage.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?><br>
</body>
</html>
The form seems to work okay but when I hit submit nothing shows up on the next page. no matter what I enter int he form, it always reads "Welcome" "Your email address is:" with nothing entered after that like its supposed to.
Do I have something configured incorrectly? Am I using the wrong browser (firefox)?
Thanks!
"I am accessing it via file:///C:/... should I be accessing it some other way instead?"
Just as I thought.
There you go. A web browser will not parse PHP directives that way.
It must be accessed as http://localhost/yourfile.xxx
Plus, a webserver and PHP need to be installed in order to parse PHP directives.
"I don't think I have Xampp or any virtual server set up... I'll look into that, any tips on where to start?"
You need to install one. Here are a few links to get you started and depending on the platform you are using.
https://www.apachefriends.org/
http://www.wampserver.com/
https://www.mamp.info
http://www.easyphp.org/
Pick your flavour.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am having trouble using the mail() function in php. I am currently learning about it at treehouse but no matter what i do, i just couldnt seem to send the email.
Previously, there were a lot of codes used to avoid spammers and bots. I tried to dumb it down to the simplest and it still wouldn't work, meaning that i still can't use it to send an email despite uploading the file to a free web host that supports php just for testing purposes using filezilla.
May I know what did i do wrong?
The webhost name is www.000webhost.com
Below is the code:
<?php
$to="theteam#theopencircles.com";
$subject="this is from your mother";
$message=$_POST["message"];
if($_POST){
mail($to,$subject,$message);
}
?>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
<input type = "text" name="message" id="message"/>
<input type = "submit" name = "submit" id="submit" value="submit"/>
</form>
</body>
</html>
<?php
if($_POST["submit"] == 'submit')
{
$to="theteam#theopencircles.com";
$subject="this is from your mother";
$headers="sender email-id";
$message=$_POST["message"];
mail($to,$subject,$message,$headers);
}
?>
you can switch to php mailer https://github.com/PHPMailer/PHPMailer phpmailer has all email related readymate functions
same time it problem from server side configuration. Please config your php.ini or contract to server admin
I am currently going through elithecomputerguy's youtube playlist for php programming. I am on part 7 of his 11 part series, this section talks about sending email with php. He writes out all the php code on notepad++ and uploads it to a standard godaddy web hosting account. I am using the same exact method, copying his code line by line, setting up the files in the same location and when I upload my email_form.php, it displays correctly
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="email_script.php" method="POST">
<p>Email Address: <input type="text" name="email" size="30"></p>
<p>Subject: <input type="text" name="subject" size="30"></p>
<p>Message: </p>
<p><textarea rows="10" cols="20" name="message"></textarea></p>
<input type="submit" name="submit" value="Submit">
</BODY>
</HTML>
Now I uploaded my email_script.php file just fine and it looks like so:
<?PHP
$from="test#mikesmtgadvice.com";
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];
mail($email, $subject, $message,"From:".$from);
print "Your message has been sent: </br?$email</br>$subject</br>$message</p>
?>
so when I go to mysite.com/test/email_form.php, it works and displays this form the way it should. However, when I fill in the form and hit submit, when it tries running the script, I get an 500 Internal Server Error. I have no idea where to look for this error and cannot find the error log, and therefore cannot figure this out. In the video, he does this exact same process and it works, is there a setting I need to change in my server or?
Thank you for your help in advance, I'm sorry for the long winded version but I wanted to be as specific as possible.
You are missing a double quote and ; at the end of the print statement:
print "Your message has been sent: <br />$email<br />$subject<br />$message</p>";
Replace that with your print line and it will fix it.
I'm having a hard time finding a solution to a problem that should have a very simple solution.
I created a PHP form mailer that worked on my customer's site. He then decided to get an SSL certificate, and since then, the form mailer doesn't work. I don't get any errors at all. Everything appears to have been sent, but I haven't received any emails from the form.
I then created a nonsense form with one field and a very basic PHP form mailer to see if I can troubleshoot the problem, but even this basic code does not work.
Does the mail() function not work with SSL? I'm thinking I'm missing something relevant somewhere. This is the first time I've worked with SSL, but I'm more than capable of creating the code if only I can get some direction, which is the reason for this post. Any guidance, direction, or critique will be very appreciated.
---MY NONSENSE FORM USED FOR TESTING---
<form id="form1" name="form1" method="post" action="testFormsub.php">
<input type="text" name="text1" id="text1" />
<input type="submit" name="button" id="button" value="Submit" />
</form>
---MY BASIC PHP FORM MAILER---
<?php
$test = $_POST['text1'];
$to="email#email.com";
$subject="Thank you for registering.";
$header="From: TEST EMAIL <email#email.com>";
$message="PLEASE WORK...$test \r\n";
$sentmail = mail($to,$subject,$message,$header);
?>
Are you using two separate pages for mailing as in a form page and results page?
If so, are you using SSL for both pages?
if not, the problem likely lies in the fact that your sendmail page uses SSL and your testFormsub.php is not using SSL.