Cannot POST php mail (Vue) - php

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?

Related

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 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.

Contact Form does not send

Having some troubles with a contact form.
When pressing submit I get redirected to http://minerva.hivolda.no/~oleav/eksamensandkasse/kontakt/ (same page), and recieve a message that my site was not found etc.
function haugsdalen_kontaktplugin () {
function haugsdalen_kontakt_header () {
echo ('<link rel="stylesheet" type="text/css" href="'.plugin_dir_url( __FILE__ ).'haugsdalen-kontakt.css">');
}
$from = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'MYMAIL';
$subject = 'Ny melding fra Haugsdalen Skisenter';
$body = "Ny melding fra Haugsdalen Skisenter:\n Fra: $name\n E-post: $email\n Melding:\n $message";
echo ('<div id="kontakthead">');
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Din melding har blitt sendt!</p>';
} else {
echo '<p>Noe gikk galt. Vennligst prøv igjen.</p>';
}
}
echo ('<form method="post" action="http://minerva.hivolda.no/~oleav/eksamensandkasse/kontakt/">
<h2>Kontakt</h2>
<label>Navn</label>
<input name="name" placeholder="Ditt navn">
<label>E-post</label>
<input name="email" type="email" placeholder="Din e-post">
<label>Melding</label>
<textarea name="message" placeholder="Din melding..."></textarea>
<input id="submit" name="submit" type="submit" value="Send inn"></form><br/>
<h3><strong>Kontaktinformasjon:</strong></h3>
Tlf: 73 85 46 05<br/>
E-post: web#haugsdalen.com<br/>
</div>');
}
Any suggestion?
Page can be found here: http://minerva.hivolda.no/~oleav/eksamensandkasse/kontakt/
EDIT:
I recieve my messages now, but the messages just contains:
Ny melding fra Haugsdalen Skisenter: Fra: E-post: Melding:
However I just recived one mail with some text:
E-post: 2#2.co Melding: 3
There is error somewhere else in your code related to the $_POST['name'] variable. When I delete this DOM node (input with name="name") and submit data everything working as expected, I've got mail function executed and your script echoed Din melding har blitt sendt!.
It seems that this script or some of your included scripts generate 404 error exception when you send any unexpected $_POST['name'] data.
I suggest you to try renaming this name="name" to name="from", for example.
Could you post the whole code of the webpage? We need to see the function calls.
Also,
Add required to each input field to reduce the number of spams or use some captcha mecanism.

My form, regarding the email bit

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

Can't get the array to work in form php

I have an issue with the checkboxes to get it working.
If none of the checkboxes have been selected, it gives an errormessage, this works fine!
Also the submitting of all other information.
I just want the form now to submit the checkboxes which have been checked into the confirmationemail. I now only get: array.
The contact.php
<?php
/* Set e-mail recipient */
$myemail = "mukies#gmail.com";
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Vul uw naam in aub");
$email = check_input($_POST['email']);
$telephone = check_input($_POST['telephone']);
$comments = check_input($_POST['comments'], "Write your comments");
$formCampagne = check_input($_POST['formCampagne']);
foreach($formCampagne as $option) {
print $option."\n";
}
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Dit e-mail adres is niet juist, voer een juist e-mailadres in.");
}
/* If telephone is not valid show error message */
if (!preg_match("/[0-9\(\)+.\- ]/s", $telephone))
{
show_error("Voer een juist telefoon nummer in");
}
/* If verification code is not valid show error message */
if (strtolower($_POST['code']) != 'mycode') {die('Voer aub de juiste code in, in hoofdletters.');}
/* If no campaign mode is selected, show error message */
if(empty($formCampagne))
{
show_error ("U heeft geen selectie gemaakt uit de campagne opties, selecteer minimaal een van de opties.");
}
/* Let's prepare the message for the e-mail */
$message = "Hi Rick,
Je hebt weer een offerte aanvraag ontvangen voor Limburg Media! :)
Name: $yourname
E-mail: $email
Telefoon: $telephone
Offerte aanvraag? $formCampagne
Comments: $comments
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: thanks.htm');
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>Gelieve de onderstaande foutmelding door te nemen om uw gegevens correct aan te leveren:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php exit();}
?> }
The Contact.htm where the visitor fills in his/her form:
<html>
<body>
<p>Benodigde velden zijn <b>vetgedrukt</b>.</p>
<form action="contact.php" method="post">
<p><b>Uw naam:</b> <input type="text" name="yourname" /><br />
<b>E-mail:</b> <input type="text" name="email" /></p>
<b>Telefoonnummer:</b> <input type="text" name="telephone" /></p>
<p>Welk soort campagne wilt u informatie over ?<br />
<input type="checkbox" name="formCampagne[]" value="sandwichborden driehoeksborden" />sandwichborden / driehoeksborden<br />
<input type="checkbox" name="formCampagne[]" value="drukwerk banners" />drukwerk / banners<br />
<input type="checkbox" name="formCampagne[]" value="evenementen outdoor" />outdoor promotie / evenemente<br />
<input type="checkbox" name="formCampagne[]" value="internet website social media" />internet / websites / social media <br />
<input type="checkbox" name="formCampagne[]" value="artwork video" />artwork / videopromotie <br />
<input type="checkbox" name="formCampagne[]" value="promo gadgets sampling" />promoteams / gadgets / sampling <br />
<input type="checkbox" name="formCampagne[]" value="mobiele reclame reclame frames" /> mobiele reclame / reclame frames <br /> </p>
<p><b>Your comments:</b><br />
<textarea name="comments" rows="10" cols="40"></textarea></p>
<p>Validatie code: <input type="text" name="code" /><br />
Vul de tekst <b>MYCODE</b> hierboven in. </p>
<p><input type="submit" value="Send it!"></p>
</form>
</body>
</html>
The thanks.htm page only contains standard text, saying, well... thank you. :)
Can anyone help me out here?
EDIT:
So this would be the correct code ?:
if(isset($formCampagne)) {
echo ".implode(',', $formCampagne)."; // this is the output in the confirmation mail
} else {
echo "U heeft geen selectie gemaakt uit de campagne opties, selecteer minimaal een van de opties.";
But where do I put it? Next to the "Offerte aanvraag?", beacuse this gives an error, as I am in the $message field already.
Sorry I have not yet worked with a isset function yet.
Try replacing
$message = "Hi Rick,
Je hebt weer een offerte aanvraag ontvangen voor Limburg Media! :)
Name: $yourname
E-mail: $email
Telefoon: $telephone
Offerte aanvraag? $formCampagne
Comments: $comments
End of message
";
with:
$message = "Hi Rick,
Je hebt weer een offerte aanvraag ontvangen voor Limburg Media! :)
Name: $yourname
E-mail: $email
Telefoon: $telephone
Offerte aanvraag? ".implode(',', $formCampagne)."
Comments: $comments
End of message
";
Notice that I've changed the plain $formCampagne with implode(',', $formCampagne), 'cause it is actually an array and you have to make it a string if you want to place it in your e-mail message.
Also notice that if none of the checkboxes are selected, $formCampagne will be NULL, so you should also check if isset($formCampagne)
EDIT:
in my example, $formCampagne should actually be $_POST['formCampagne'], I must admit I never used the check_input() function and do not really know how it behaves on arrays.
You could also try to var_dump() the content of both $formCampagne and $_POST['formCampagne']
You can check for isset($formCampagne) if returns false, that means none of the checkbox is selected, else it will give you array of values.
$message = "Hi Rick,
Je hebt weer een offerte aanvraag ontvangen voor Limburg Media! :)
Name: $yourname
E-mail: $email
Telefoon: $telephone
Offerte aanvraag? $formCampagne
Comments: $comments
End of message
";
Instead of $formCampagne, you should try something like this:
$message = "Hi Rick,
Je hebt weer een offerte aanvraag ontvangen voor Limburg Media! :)
Name: $yourname
E-mail: $email
Telefoon: $telephone
Offerte aanvraag? ".implode(', ', $formCampagne)."
Comments: $comments
End of message
";
That should give a list of all the selected checkbox values separated by commas.

Categories