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/");
?>
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 email form shooting blank emails
(4 answers)
Closed 2 years ago.
I have a contact form on two different websites I have made for clients.
At around 8-9pm everyday a blank message is sent using the contact form and straight to my clients' respective email addresses.
PHP:
<?php
$name = $_POST['full-name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = $_POST['full-name'];
$to = 'mobileguitarworkshop#hotmail.com';
if(!empty($_POST['field'])) die();
$email_from = 'mobileguitarworkshop#hotmail.com';
$email_subject = "Enquiry from $name.\n";
$body = "From: $name.\n".
"Email: $email.\n".
"Message: $message.\n";
$headers = "From: $email \r\n";
$headers .= "Reply-To: $email \r\n";
mail($to, $email_subject, $body, $headers);
header("Location: http://mobileguitarworkshop.co.uk/success.html");
exit();
?>
HTML:
<form action="contact.php" method="post" class="contact-form">
<label for="full-name">Name</label>
<input name="full-name" type="text" id="full-name" required>
<input type="text" id="field" name="field"/>
<label for="phone">Phone</label>
<input name="phone" type="tel" id="phone">
<label for="email">Email address</label>
<input name="email" type="text" id="email" required>
<label for="message">Message</label>
<textarea name="message" id="message"></textarea>
<input name="send" type="submit" value="SEND" id="sendBtn">
</form>
I've tried adding 'required' to the Name and Email Address inputs to stop spammers, and also a hidden field that, if filled, directs them to 'success.html' without posting the message.
If anyone can explain why this is happening that would be great. The hosting service I'm using is 1&1 IONOS.
Thanks,
Jack
The spammers may be sending a request directly to the contact form endpoint, bypassing your form entirely. This means that required fields in the html wont do much to stop that. You'll need to check those properties on the backend to prevent those submissions. Something like this would work:
if(empty($_POST['full-name']) || empty($_POST['email'])) {
die();
}
If I were you, I'd also look into implementing a CSRF token. See How to properly add CSRF token using PHP
While we're talking, we really should sanitize the $_POST['message']; with something like the below to remove any questionable html content your users may have submitted:
$message = strip_tags($_POST['message']);
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.
I've already spend hours on this simple code. Email arrives, but fields like name email newsletter are empty. It must be something stupid but it drives me crazzy that it's not working when it's just simple form.
Also, if you know, can you please help me prevent user from clicking on form twice and sending multiple emails. Thank you a lot!
<?php
$name = strip_tags(htmlspecialchars($_GET['name']));
$email_address = strip_tags(htmlspecialchars($_GET['email']));
$message = strip_tags(htmlspecialchars($_GET['message']));
$newsletter = strip_tags(htmlspecialchars($_GET['newsletter']));
// Create the email and send the message
$to = 'xxx#xxx.com';
$email_subject = "Message from from : $name";
$email_body = "Message from form arrived.\n\n"."Message details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $newsletter\n\nMessage:\n$message";
$headers = "From: form#xxx.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
?>
<form method="GET">
<span>Name</span>
<input type="text" name="name" placeholder="Your name"><br />
<span>E-mail</span>
<input type="email" name="email" placeholder="E-mail"><br />
<div>Message</div>
<textarea type="text" name="message" rows="8" cols="80"></textarea><br />
<input type="checkbox" name="newsletter" id="newsletter">
<label for="newsletter">I wold like to get email infromations</label><br />
<button type="submit">Send</button>
<span class="message"></span>
</form>
You may prefer HEREDOC syntax when working with lengthy strings that include variables, like you would use to generate email content. If your variables are being populated correctly, then this should work.
$email_body = <<<EOT
Message from form arrived.
Message details:
Name: $name
Email: $email_address
Phone: $newsletter
Message:
$message
EOT;
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()