I've searched stack but couldn't find something similar. I found a nice php script with a robot attached to the form. It works when I send a message and I do receive it. BUT, the email bit doesn't show up in the mail. Maybe you can find something more that is wrong. It's all in Swedish so nevermind the text :P
<?php
if($_POST){
$to = 'my#mail.com';
$subject = 'Portfolio-mail';
$from_name = $_POST['name'];
$from_email = $_POST['email'];
$message = $_POST['message'];
$robotest = $_POST['robotest'];
if($robotest)
$error = "* Misstänkt för att vara en robot, vad god försök igen!";
else{
if($from_name && $from_email && $message){
$header = "Från: $from_name, $from_email";
if(mail($to, $from_email, $from_name, $message))
$success = "Ditt meddelande har skickats!";
else
$error = "* Du är mänsklig, men det var ett fel med din förfrågan!";
}else
$error = "* Alla fält måste vara ifyllda!";
}
}
?>
And for the input bit:
<form action="" method="POST" autocomplete="off">
<div class="formLeft">
<label>För- & Efternamn:</label>
<input type="text" id="name" name="name" placeholder="John Doe" required="required">
<label>Email-adress:</label>
<input type="text" id="email" name="email" placeholder="Fyll i din email-adress!" required="required">
</div>
<div class="formRight">
<label>Skriv gärna in några ord angående projektet.</label>
<textarea id="textarea" name="message" placeholder="Klicka i denna ruta för att börja skriva..." required="required"></textarea>
<p class="robotic" id="pot">
<label>If you're human leave this blank:</label>
<input name="robotest" type="text" id="robotest" class="robotest" />
</p>
<input type="submit" value="Skicka!" />
</div>
</form>
That's it! If you need more information, don't hesitate to ask!
You are using the php mail function incorrectly:
mail($to,$subject,$message,$headers);
You have
if(mail($to, $from_email, $from_name, $message))
With your code you have many of these variables you just aren't using them, it should be
if(mail($to, $subject, $message, $header))
In the future please at least look at the php documentation before posting a question. http://php.net/manual/en/function.mail.php
Related
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
I am building a really small webapp in Vue with a simple contact form as component. I would like to use a really basic php script for sending the mail. I am not an expert on PHP but for some reason I can't figure out this bug I get when I try to submit the contact form. It says
Cannot POST /mail_contact.php
HTML/Vue component
<form class="contact" action="mail_contact.php" method="post">
<div class="container">
<input type="text" class="st-input" placeholder="Vul hier jouw naam in" name="name">
<input type="text" class="st-input" placeholder="Vul hier kort en bondig jouw probleem in" name="problem">
<input type="text" class="st-input" name="email" placeholder="Vul hier jouw e-mail adres in">
<input type="text" class="st-input" placeholder="Vul hier jouw telefoonnummer in" name="tel">
<select name="telOrEmail" required><option disabled>Maak een keuze</option><option value="Tel">Telefoon</option><option value="Email">Email</option></select>
</div>
<button class="send-button" type="submit">Verzenden!</button>
</form>
PHP Script
<?php
if(isset($_POST['submit'])) {
//getters from form
$name = $_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$problem = $_POST['problem'];
$telOrEmail = $_POST['telOrEmail'];
//mail content
$formcontent=" Van: $name \n Telefoonnummer: $tel \n Emailadres: $email \n Problem: $problem \n Terugbellen of Emailen: $telOrEmail";
//ontvanger van mail
$recipient = "g.gijsberts#sqits.nl";
//Onderwerp
$subject = "Contact formulier Sqits-it";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Bedankt voor je bericht! Wij hopen zo snel mogelijk te reageren.";
}
?>
Is there something I just don't see?
Edit
Project structure
index.html (File)
src (Directory) -> App.vue, main.js, router.js, components (directory) -> Contact.vue
dist (Directory) -> build.js, build.js.map, index.html, mail_contact.php
mail_contact.php (File)
So as you can see I've place my php script in the same directory as the main file (Index.html), but also in the directory where the build file is placed. Good point to say is this is a Vue project.
For a weird reason I get a 404 error (on localhost:8080/mail_contact.php) when submitting the form before I am redirected to the blank page with the Cannot POST /mail_contact.php. How is this possible if the file is actually there in my directory?
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
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.
I am new to PHP, and I made this PHP Mail, for a regular contact form... When the form is completed, the page is redirected and displays "The message was sent succesfully". The problem is, i don't want the page to redirect.. I want to show a feedback on the index, something like a success modal box or a simple text underneath the form "your message was sent"...
Any ideas on how to do this?
<?php
$nome = $_POST['nome'];
$email = $_POST['email'];
$emaildestino = 'contato#zerodesign.com.br';
$email_from='contato#zerodesign.com.br';
$mensagem = $_POST['mensagem'];
$assunto = $_POST['assunto'];
$telefone = $_POST['telefone'];
$titulo = 'Mensagem - TESTE';
<?php
$nome = $_POST['nome'];
$email = $_POST['email'];
$emaildestino = 'contato#zerodesign.com.br';
$email_from='contato#zerodesign.com.br';
$mensagem = $_POST['mensagem'];
$assunto = $_POST['assunto'];
$telefone = $_POST['telefone'];
$titulo = 'Mensagem - TESTE';
$juntando = '<p>Esta mensagem foi enviada pelo site</p><br/>
<p><b>Nome:</b> '.$nome.'</b></p><br>
<p><b>Email:</b> '.$email.' </b></p><br>
<p><b>Telefone:</b> '.$telefone.'</p> </br>
<p><b>Mensagem:</b></p>
<p><i>'.$mensagem.'</i></p>
<hr>';
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= "From: $email_from " . "\n";
$envio = mail($emaildestino, $titulo, $juntando, $headers, "-r".$email_from);
if($envio)
echo "Mensagem enviada com sucesso";
else
echo "A mensagem nãpode ser enviada";
?>
Here is my form:
<form method="POST" name="contactform" action="envia.php">
<p><input id="inputt" type="text" name="nome" placeholder="Nome" id="nome" ></p>
<p><input id="inputt" type="text" name="email" placeholder="Email" id="email"></p>
<p><input class="inputt" type="text" name="telefone" placeholder="Telefone" id="telefone"> </p>
<p><textarea id="mensagem" name="mensagem" rows="5" cols="40" placeholder="Mensagem" id="mensagem"></textarea></p>
<input id="button" type="submit" value="Enviar"><br>
</form>
If i understand correctly, what you want to do is not visit the envia.php page, you'll need to send an AJAX call there instead. When the ajax call finishes, you can use javascript to update your index page with the success message.
I believe you are looking for something like:
PHP script added to the top of the form page redirecting to the same page
if(isset($_POST['nome'], $_POST['email'], $_POST['mensagem'], $_POST['assunto'], $_POST['telefone']){
...
$envio = mail($emaildestino, $titulo, $juntando, $headers, "-r".$email_from);
if($envio){
$msg = "Mensagem enviada com sucesso";
}else{
$msg = "A mensagem nãpode ser enviada";
}
}
HTML:
<form method="POST" name="contactform" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<p><input id="inputt" type="text" name="nome" placeholder="Nome" id="nome" ></p>
<p><input id="inputt" type="text" name="email" placeholder="Email" id="email"></p>
<p><input class="inputt" type="text" name="telefone" placeholder="Telefone" id="telefone"> </p>
<p><textarea id="mensagem" name="mensagem" rows="5" cols="40" placeholder="Mensagem" id="mensagem"></textarea></p>
<input id="button" type="submit" value="Enviar"><br>
<span id="msg"><?php if(isset($msg)){echo $msg;}?></span>
</form>
looking at your site you might want to add the <?php if(isset($msg)){echo $msg;}?> to the top of the page or add a js script that scrolls to the bottom of the page
Just make the action attribute empty like...
<form method="POST" name="contactform" action="">
So, the page will submit to itself.