PHP contact form is not sending email. [duplicate] - php

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

Related

PHP contact form doesn't send emails [duplicate]

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

Routine spam on php contact form [duplicate]

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']);

PHP mail function not working on Hostgator [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
this is my site:
http://feriapixel.cl...nway/index.html
I've been trying other stuff and now i have the php code and the form in the same index.php file.
The form now looks like this
<form action="index.php" method="post">
<div class="form-group">
<input type="text" class="form-control" id="nombre" placeholder="Nombre" name="nombre">
</div>
<div class="form-group">
<input type="text" class="form-control" id="apellido" placeholder="Apellido" name="apellido">
</div>
<div class="form-group">
<input type="text" class="form-control" id="telefono" placeholder="Número Móvil" name="telefono">
</div>
<div class="form-group">
<input type="mail" class="form-control" id="email" placeholder="Email" name="email">
</div>
<button type="submit" name="submit" id="submit" class="btn btn-ganarplata">QUIERO GANAR MÁS PLATA<br> VENDIENDO CLEAN WAY</button>
</form>
And i have the php at the beginning of the file like this:
<?php
$nombre = $_POST['nombre'];
$apellido = $_POST['apellido'];
$telefono = $_POST['telefono'];
$mail = $_POST['mail'];
$from = 'From: Cleanway';
$to = 'alteizen#gmail.com';
$subject = 'Formulario de contacto Cleanway';
$body ="De: $nombre\n $apellido\n E-Mail: $mail\n Fono: $telefono\n ";
?>
<?
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Su mensaje ha sido enviado</p>';
} else {
echo '<p>No se pudo mandar su mensaje</p>';
}
}
?>
And now i have checked out and it is not a hosting issue, because if i take out the following if statement:
if ($_POST['submit']) {
The mail is automatically sent when i load the page. So the problem is with the if statement, something is wrong there.
Problem solved, this was missing:
QUIERO GANAR MÁS PLATA VENDIENDO CLEAN WAY
The button needed a "submit" value for sending the mail. That was all, thanks to me.
You need to add an email address to $headers so that when you mail, the from address can be seen. Actually, your web server needs an MX record. Use it like this.
NOTE: If you use an email that is not your website's email(like xxx#gmail.com) it won't gonna work.
$headers .= "From: Name <email#example.com>";
So I think this will gonna work.

PHP Contact Form doesn't deliver mails [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
My contact form won't work. The messages aren't sent to the given email address.
The form successes but the emails aren't delivered. The other question has another code using if tags, which won't work for my script.
The html code I used is:
<form class="form" id="form1" action="mail.php" method="post">
<p class="name">
<input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="NAME" id="name" />
</p>
<p class="email">
<input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="E-MAIL" />
</p>
<p class="text">
<textarea name="text" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="WHAT'S UP?"></textarea>
</p>
<div class="submit">
<input type="submit" name="submit" value="SEND" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
The PHP script I use is:
<?php
// We create a variable for name value
$name = $_POST['name'];
// We create a variable for email value
$email = $_POST['email'];
// We create a variable for message value
$message = $_POST['text'];
// We provide an e-mail address from which the email is sent
$from = "xyz#adress.com";
// Provide the e-mail address on which you want to receive messages
$to = "xyz#gmx.de";
// Provide the subject of the e-mail
$subject = "Contact form from xyz.com";
// We prepare the message body
$emailbody = "";
$emailbody .= "Message: " . $message . "\n";
// We add UTF-8 to the header of our message
$header = "";
$header .= "From:" . $from . " \n";
$header .= "Content-Type:text/plain;charset=utf-8";
// Sending message
$success = mail($subject, $emailbody, $header);
// Redirect after sending the message
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=de/confirmation_signup.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=de/error.html\">";
}
?>
Anybody has a clue what is going wrong inside the form?
You are passing vars to mail function wrong;
Change this:
mail($subject, $emailbody, $header);
To this:
mail($to,$subject, $emailbody, $header);
See: http://php.net/manual/en/function.mail.php

PHP Mail Form not sending [duplicate]

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.

Categories