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
Related
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:
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 4 years ago.
I honestly can't find out what is wrong with the code. Could someone please help? I just want it to send the input to my email. And yes, it an email associated with my host.
The PHP:
<?php
if (isset($_POST['submit'])) { .
$name = $_POST['name'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "my#email.com";
$headers = "De: " .$mailfrom;
$txt = "Você recebeu um email de ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
The HTML:
<form id="contact" action="contactform.php" method="post">
<h3>Deixe a sua mensagem.</h3>
<input placeholder="Seu Nome" name="name" type="text" tabindex="1" required autofocus oninvalid="this.setCustomValidity('Favor digitar nome válido.')" oninput="setCustomValidity('')">
<input placeholder="Seu E-Mail" name="mail" type="email" tabindex="2" required oninvalid="this.setCustomValidity('Favor digitar Email válido.')" oninput="setCustomValidity('')">
<textarea placeholder="Digite sua mensagem aqui..." tabindex="5" name="message" required oninvalid="this.setCustomValidity('Favor digitar mensagem válida.')" oninput="setCustomValidity('')"></textarea>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">ENVIAR</button>
</form>
Yeah it's a mess, sorry about that.
what is that .?
if (isset($_POST['submit'])) { . <--------
I would try removing that period. Unless it's a speck on my monitor. haha!
If that isn't the problem, then it could be your smtp settings aren't set properly
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()
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I know this is a popular question. However no other questions can give me the answer I'm looking for.
Have a contact form (mail() being using. And I can't get it to send. A coder that helped me create it somehow got his to send, because I received a few messages in my inbox the mail was coded to send to. I copy and pasted the code, and I'm testing it locally, but it's not sending the mail.
Is the problem it's not sending because I'm testing it locally and its not live and hosted yet? or does the problem rely in my code, and if so, where?
***Not including the validation code, but I have it there...
FORM:
<form method="post" action="">
<input type="text" name="name" placeholder="*Name" value="<?php echo $_POST['name']; ?>">
<input type="tel" name="phone" placeholder="*Phone Number" value="<?php echo $_POST['phone']; ?>">
<input type="email" name="email" placeholder="*Email" value="<?php echo $_POST['email']; ?>">
<input type="text" name="invoice" placeholder="Invoice Number (optional)" value="<?php echo $_POST['invoice']; ?>">
<textarea name="comments" maxlength="500" rows="10" cols="10" placeholder="*Please enter your comments here..."><?php echo htmlentities($_POST['comments'], ENT_COMPAT,'ISO-8859-1', true);?></textarea>
<button type="submit">Submit</button>
</form>
PHP:
if(!empty($_POST)){
$POST = filter_post($_POST);
$invoice = array_splice($POST,3,1);
$MSG = check_empty($POST);
$email = test_input($_POST["email"]);
if(!array_filter($MSG)){
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$MSG[] = "Invalid Email Format (test#provider.com)";
}
else{
$POST['invoice'] = $invoice['invoice'];
if(send_mail($POST)){
header('Location: messageSent.php');
}
else{
$MSG[] = "Email Failed. Please Try Again.";
}
}
}
}
function send_mail($POST){
extract($POST);
$to = '7servicerepairs#gmail.com';
$sbj = 'New Question For Se7en Service!';
$msg = "Name: $name \n Phone: $phone \n Email: $email \n Invoice #: $invoice \n Comments: $comments";
$headers = "From: $email";
return(mail($to, $sbj, $msg, $headers));
}
You will need an smtp server in your localhost. Otherwise you won't be able to send it.