PHP mail function not working on Hostgator [duplicate] - php

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.

Related

Email not sending anymore form.php [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 months ago.
sinds a couple of days my form has stopped working.
I'm not really familiar with PHP and i have no idea how to get it working again.
I'm hosting my site on one.com , it has been working fine for about a year now, and suddenly it stopped working?
I've been searching the internet and i'm finding all kinds of answers 'you have to update your php code...' but i'm not familiar with PHP so please help :D
The form.php :
<?php
/* Set e-mail recipient */
$myemail = "info#kongweb.be";
/* Check all form inputs using check_input function */
$naam = check_input($_POST['naam']);
$mail = check_input($_POST['mail']);
$bericht = check_input($_POST['bericht']);
/* Let's prepare the message for the e-mail */
$message = "Hallo!
Wij ontvingen een contactformulier met de volgende gegevens:
Naam: $naam
E-mailadres: $mail
Message: $bericht
Einde van dit bericht.
";
/* Send the message using mail() function */
$headers = "From: info#kongweb.be";
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location:bedankt.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
And the code for the contact form on the index.html :
<!-- contact begin -->
<div id="contact" class="container-fluid text-center tekst2">
<h1>Contact</h1>
<form name="contact" method="post" action="https://kongweb.be/form.php" onsubmit="return validateForm()" >
<input type="hidden" name="subject" value="contact">
<div class="row slideanim spatieform">
<div class="col-sm-12">
<input type="text" name="naam" size="30" id="naam" required placeholder="Name">
</div>
</div>
<div class="row slideanim spatieform">
<div class="col-sm-12">
<input type="text" name="mail" size="30" id="mail" required placeholder="Email">
</div>
</div>
<div class="row slideanim spatieform">
<div class="col-sm-12">
<textarea name="bericht" id="bericht" cols="30" rows="8" required placeholder="Message"></textarea>
</div>
</div>
<div class="row slideanim spatieform">
<div class="col-sm-12">
<input type="submit" name="submit" value="Send it" style="background-color: #F3E600">
</div>
</div>
</form>
</div>
<!-- contact einde -->
This will escape your input a bit and give you some error messages for debug. Unless you are sending the email to yourself you need a $to variable and you were missing a $subject , which is also required or will not work. This is a very simple way to do this. There are lots of other like looping through the $_POST for instance. I also suggest reading https://www.php.net/manual/en/function.mail.php
Example Fix to your question:
// you can make sure its set and escape it also. Must be cleaned when user input.
if(isset('submit')){
$naam = mysqli_real_escape_string($con, $_POST['naam']);
if(!isset($coops) || empty($coops)){
$json_array['error'] = true;
$json_array['message'] = "Coops not set.";
$json = json_encode($json_array);
echo($json);
exit;
}
$mail = mysqli_real_escape_string($con, $_POST['mail']);
if(!isset($mail) || empty($mail)){
$json_array['error'] = true;
$json_array['message'] = "mail not set.";
$json = json_encode($json_array);
echo($json);
exit;
}
$bericht = mysqli_real_escape_string($con, $_POST['bericht']);
if(!isset($bericht) || empty($bericht)){
$json_array['error'] = true;
$json_array['message'] = "bericht not set.";
$json = json_encode($json_array);
echo($json);
exit;
}
$headers = "From: info#kongweb.be";
$myemail = "info#kongweb.be";
$subject = "Your subject"; // was missing and must have
$message = "Hallo!
Wij ontvingen een contactformulier met de volgende gegevens:
Naam: $naam
E-mailadres: $mail
Message: $bericht
Einde van dit bericht.";
mail($myemail, $subject, $message);
}
header('Location:bedankt.html');
exit();
are you sending the email to yourself. Otherwise you need a $to in place of you $myemail but without $subject being intialized it would never work. Redirect visitor to the thank you page
to Mail address to which you want to send mail Required
subject Subject of the mail Required
message Message to be sent with the mail. Each line of the message should be separated with a LF (\n). Lines should not be larger than 70 characters. Required

PHP contact form is not sending email. [duplicate]

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

Php form does not send [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I've tried to built a php form. However, it won't send.
html (index.html):
<div class="row">
<div id="Contact" class="container">
<h1>Meer weten?</h1>
<h2>Neem vrijblijvend contact op</h2>
<div id="ContactBlock">
<form class="contactform" method="post" action="submitform.php">
<div class="FormTop">
<div class="half-left-cf">
<input type="text" id="input-name" name="name" placeholder="Naam (verplicht)">
<input type="text" id="input-email" name="email" placeholder="Email address (verplicht)">
<input type="text" id="input-telnr" name="telnr" placeholder="Telefoonnummer">
</div>
<div class="half-right-cf">
<textarea name="message" type="text" id="input-message" name="message" placeholder="Uw bericht"></textarea>
</div>
</div>
<label>*Hoeveel is is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Antwoord hier">
<input type="submit" value="Verzenden" id="input-submit">
</form>
</div>
</div>
php (submitform.php):
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$telnr = $_POST['telnr'];
$message = $_POST['message'];
$from = 'From: Contact Form';
$to = 'e-mail';
$subject = 'Hello';
$human = $_POST['human'];
$body = "Afkomstig van: $name\n E-Mail: $email\n Telnr:\n $telnr Bericht:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Uw bericht werd goed verzonden. Wij contacteren u zo snel mogelijk.</p>';
} else {
echo '<p>Er is iets misgegaan, probeer a.u.b. opnieuw!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>U heeft de anti-spam vraag niet correct ingevuld</p>';
}
} else {
echo '<p>U heeft niet alle verplichte velden ingevuld</p>';
}
}
?>
When I press submit the browser returns a blanc page with /.../submitform.php in the url-bar.
This happens both in an online environment as well as on localhost.
Am I doing something wrong? Thanks
If you not sure about your folder structure just use this simple trick.
Change post url to absolute one like http://www.example.com/xyz/submitform.php
In local
http://www.localhost/xyz/submitform.php
Instead of trying simple submitform.php

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

Configuring My PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hey I am trying to figure out my problem with my form and where my hangups are in the code. Anyone have any suggestions?
<form method="post" action="tourney.php">
<div class="row">
<div class="col-sm-4">
<input class="form-control" type="text" placeholder="Name" name="tname">
</div>
<div class="col-sm-4">
<input class="form-control" type="text" placeholder="Email" name="temail">
</div>
<div class="col-sm-4">
<input class="form-control" type="text" placeholder="School or Club" name="tclub">
</div>
<br>
<br>
<div class="col-sm-4">
<input class="form-control" type="text" placeholder="Address" name="taddress">
</div>
<div class="col-sm-3">
<input class="form-control" type="text" placeholder="City" name="tcity">
</div>
<div class="col-sm-2">
<input class="form-control" type="text" placeholder="State" name="tstate">
</div>
<div class="col-sm-2">
<input class="form-control" type="text" placeholder="Zip" name="tstate">
</div>
</div>
<br>
<div class="row">
<div class="col-sm-12">
<textarea placeholder="Type your message here..." class="form-control" rows="5"></textarea>
</div>
</div>
<br>
<div class="row">
<div class="col-sm-6">
<select name="type" class="form-control">
<OPTION VALUE="None Selected" SELECTED>Please select one</OPTION>
<OPTION VALUE="Middle School">Middle School Tournamanet</OPTION>
<OPTION VALUE="Elementary">Elementary Tournament</OPTION>
</select>
</div>
<div class="col-sm-6 pull-right">
<input class="btn btn-danger" type="submit" value="Register">
</div>
</div>
</form>
and the PHP to send the email:
<?php
if(isset($_POST['submit'])){
$from = "minguswrestling.com";
$to = "puremeld#gmail.com";
$name = $_POST['tname'];
$email = $_POST['temail'];
$school = $_POST['tclub'];
$address = $_POST['taddress'];
$city = $_POST['tcity'];
$state = $_POST['tstate'];
$zip = $_POST['tzip'];
$type = $_POST['type'];
$message = $_POST['tmessage'];
$subject = "Tourney Signup!";
$body = "From: $from \n Name: $name \n Email: $email \n School: $school\n Address: $address\n City: $city State: $state Zip: $zip\n Event: $type\n Message: $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
'<h2>Thank You!</h2>';
header("Location: index.html");
} else {
echo '<p>Oops! An error occurred. Try sending your message again. </p>';
}
}
}
?>
Any help would be appreciated. I am using bootstrap for my build, thank you.
There are a few things wrong with your code.
Firstly, and as I mentioned in comments; everything inside the following conditional statement will never fire up:
if(isset($_POST['submit'])){...}
because there is no form element that is named "submit", being your submit button and error reporting would have thrown you an undefined index submit notice....
Therefore you need to modify it to read as:
<input name="submit" class="btn btn-danger" type="submit" value="Register">
However, you have a second if ($_POST['submit']) { that needs to be removed; it's not needed.
You also have no name attribute for:
<textarea placeholder="Type your message here..." class="form-control" rows="5"></textarea>
that needs to be modified to and adding name="tmessage" since $message = $_POST['tmessage']; is most likely to be used for the message:
<textarea name="tmessage" placeholder="Type your message here..." class="form-control" rows="5"></textarea>
Also, you've used the same name here for both "state" and "zip":
<input class="form-control" type="text" placeholder="Zip" name="tstate">
which should read as:
<input class="form-control" type="text" placeholder="Zip" name="tzip">
Then, you're outputting before header having the '<h2>Thank You!</h2>'; and header:
Sidenote: You may have meant to do echo '<h2>Thank You!</h2>';, yet that would still constitute as outputting before header, because PHP is actually throwing you a parse error, but your server is probably not set up to catch and display notices/errors etc.
if (mail ($to, $subject, $body, $from)) {
'<h2>Thank You!</h2>';
header("Location: index.html");
}
You need to choose from "one" of those and not both. Either modify '<h2>Thank You!</h2>'; to read as echo '<h2>Thank You!</h2>'; and remove the header, or remove the "Thank you" and use header.
Consult the following on Stack about outputting before header:
How to fix "Headers already sent" error in PHP
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Displaying errors should only be done in staging, and never production.
Here's a rewrite and see the embedded comments:
<?php
if(isset($_POST['submit'])){
$from = "minguswrestling.com";
$to = "puremeld#gmail.com";
$name = $_POST['tname'];
$email = $_POST['temail'];
$school = $_POST['tclub'];
$address = $_POST['taddress'];
$city = $_POST['tcity'];
$state = $_POST['tstate'];
$zip = $_POST['tzip'];
$type = $_POST['type'];
$message = $_POST['tmessage'];
$subject = "Tourney Signup!";
$body = "From: $from \n Name: $name \n Email: $email \n School: $school\n Address: $address\n City: $city State: $state Zip: $zip\n Event: $type\n Message: $message";
if (mail ($to, $subject, $body, $from)) {
echo '<h2>Thank You!</h2>'; // either use echo
// header("Location: index.html"); // or header, not both. Comment one or the other out.
} else {
echo '<p>Oops! An error occurred. Try sending your message again. </p>';
}
}
else { echo "Submit is not set."; }
?>
Footnotes:
It would be best to also use !empty() against your POST arrays, since anyone could use your form and pass empty values.
Reference:
http://php.net/manual/en/function.empty.php
Plus, $from = "minguswrestling.com"; be careful with that. mail() expects that to be an E-mail address and not a domain and may end up in Spam.
Best to use a From: as stated in the manual.
Consult the manual:
http://php.net/manual/en/function.mail.php
Final notes.
It's unclear if you're using this from your own PC or a hosted service.
If it's from your own PC, then a Webserver needs to be installed and properly configured, including PHP and mail.
If from a hosted service, make sure that mail is made available to you.
Check your Spam also when testing.
If you're going to use header, add exit; for it, otherwise your code may want to continue executing:
header("Location: index.html");
exit;
Remember not to use the "echo" if you're going to use header.
The following:
'<h2>Thank You!</h2>';
header("Location: index.html");
Is wrong, you cannot output anything before a header. Remove:
'<h2>Thank You!</h2>';

Categories