This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have a contact form on my website and it does not seem to be sending emails. It was on a server when I have been testing it.
Here is the form.
<form action="" method="post" name="form">
<input type="text" name="name" />
<input type="email" name="email" />
<textarea name="message" ></textarea>
<input name="submit" type="submit" value="Submit">
</form>
And here is the PHP code.
<?php
if(isset($_POST["submit"])){
if($_POST["name"]==""||$_POST["email"]==""||$_POST["message"]==""){
echo "Please fill in the contact form";
}else{
$to = "example#gmail.com";
$subject = "Contact Form";
$name= $_POST['name'];
$email= $_POST['email'];
$message= $_POST['message'];
$headers = "From: example#gmail.com";
mail($to,$subject,$name,$email,$message,$headers);
}
}
?>
I have changed my email address to a dummy one there but it does I have not recieved any emails when I do submit this form though.
Thanks in advance! :)
<?php
$to = "somebody#example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$txt,$headers);
//syntax mail(to,subject,message,headers,parameters);
?>
The php mail-function requires a different set of parameters:
Php Mail function
You have to embed $name and $email into your message before passing it to php's mail()
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 1 year ago.
I have been working on a contact form for my site, but I don't receive emails. I'm not sure what I'm doing wrong. If it helps, I'm hosting on DreamHost.
HTML
<form action="php/contact.php" method="post">
<input type="text" name="name" placeholder="Name...">
<input type="text" name="mail" placeholder="Email...">
<input type="text" name="subject" placeholder="Subject...">
<textarea name="message" placeholder="Message..."></textarea>
<button type="submit" name="send">SUBMIT</button>
</form>
PHP
<?php
if (isset($_POST['send'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "email#email.com";
$headers = "From: Commissioner";
$txt = "Commission from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: ../commissions.php?error=mailsent");
}
you need a mailer or support from the hoster (most hosting block the mailer)
you can use phpMailer
see https://help.dreamhost.com/hc/en-us/articles/215842658-PHPMailer-overview
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I have created a simple php file to capture emails from users who are signing up for a newsletter. The 'captured email' is not getting sent through to me. The email I receive is this 'Email: ' without the users email.
<?php
session_start();
//require_once('recaptchalib.php');
$privatekey = "6Ldni7wUAAAAAIMRGmqhTeehXqkx0ZC";
$publickey = "6Ldni7wUAAAAAKO37aO2hfy3kHyXTuN";
$email = $_POST['email'];
$admin_email = 'example#email.com';
$email_from = 'example#email.com';
$email_subject = "Newsletter Signup";
$email_body = "Email: $email \r\n";
$to = "$admin_email";
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: thankyou.html");
?>
HTML
<form method="POST" action="newsletter.php">
<input type="text" name="newsletter" title="" placeholder="Email Address..." required>
<button type="submit">Sign Up</button>
<div class="clearboth"></div>
<div class="g-recaptcha" data-sitekey="6Ldni7wUAAAAAKO37aO2hfy3kHyXTuN"></div>
<label><input name="consent" type="checkbox" class="input-name" required>
<span class="captchaspan obligatorycheck"><!--Some text--></span>
</label>
</form>
$email_body = "Email: $contact \r\n";
You have never defined $contact.
This question already has answers here:
How do I send email on heroku using PHP?
(2 answers)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I'm trying to make my form work so I can receive emails. My website is currently stored on Heroku and everything looks fine, except it doesn't send emails after the form is submitted. Can someone help me please?
index.php :
<form id="contact-form" method="post" action="email.php">
<input class="holder" placeholder="Name" type="text" name="name" required>
<input class="holder" placeholder="Email" type="email" name="email" required>
<textarea class="holder" placeholder="Drop me some lines" type="text" name="message"></textarea>
<div class="button-position">
<button id="button-submit" type="submit"><p id='submit_word'>Submit</p><img class="send-spaceship" src="resources/css/images/send-spaceship.png"></button>
</div>
</form>
email.php:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = "itzikshaoulian#gmail.com";
$email_subject = "Form Submission";
$email_body = "User Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$to = "itzikshaoulian#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: https://itzikshaoulianportfolio.herokuapp.com/");
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I been spending hours and still can't figure it out. New to PHP mail form coding. Any help would truly be appreciated! Two images below: the html and php. Pretty simple setup. I get the echo 'thank you!!' message after clicking send button, but I still don't receive any emails at all.
HTML Form:
<form action="assetslphplmail.php" method="POST">
<input placeholder="NAME" type="text" name="name">
<input p1aceholder="EMAIL" type="email" name="email">
<input p1aceholder="TELEPHONE" type="te1" name="te1">
<input p1aceholder="SUBJECT" type="text" name="subjectline">
<textarea p1aceholder="COMMENT" name="message" rows="6" cols="25" </textarea>
<input c1ass="send_button" type="submit" value="SEND">
</form>
PHP Code:
$subject1ine = $_REQUEST['subject1ine'];
$name = $_REQUEST['name'];
$emai1 = $_REQUEST['emai1'];
$tel 1' $_REQUEST['teI'];
$message = $_REQUEST['message'];
$to = "jondergmai1.com";
mail ( $to, $subjectline, $name, $emai1, $tel, $message);
echo 'Thank you!!';
Replace your PHP code with following:
<?php
$subject = $_REQUEST['subjectline'];
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$tel = $_REQUEST['tel'];
$message = $_REQUEST['message'];
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To:'.$email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$to = "jonder#gmail.com";
mail($to, $subject, $message, $headers);
echo 'Thank you!!';
?>
Edit From and Reply-To part.
Here are the plenty of similar answers: PHP Mail form doesn't send email
Okay, so I've got a VPS with sendmail running as well as php5. The mail server works because I tested somebody elses php contact script and it succesfully sent me an email via a submit button. I can't however seem to get my script to work. Here it is:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = $visitor_email;
$email_subject = "You got work yo!";
$email_body = $message
$to = "myemail#gmail.com";
$headers = "from: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
Here is the html
<form action="email.php" name="emailform" method="post">
Name:<input type="text" name="name">
<br/>
Email:<input type="text" name="email">
</br>
Message:<input type="text" name="message">
<input type="submit" value="Send Form">
</form>
Thanks for the help
You have a syntax error: you are missing a semicolon after $email_body = $message. This is causing your script to fail with a white screen.
Tip for the future: if you had any output in your PHP or checked the logs, you would have caught this.