0

I have an index.html and a contacto.php.

contacto.php is supposedly meant to send the user's info to multiple recipients but it's not sending.

This is my index.html (ignore the javascript)

<form action="contacto.php" method="POST">

        <fieldset style="margin: 0px 0 0 0"; >
<br/><br/>  <br/><br/>  <br/><br/>  <br/><br/>


<input maxlength="255" name="Form testing" size="20" type="hidden" value="Form-name-here" /><br>    

 <input value="Nome" onfocus="if (this.value == 'Nome') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Nome';}" maxlength="255" name="name" size="20" type="text" /><br>

<input value="Telemóvel" onfocus="if (this.value == 'Telemóvel') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Telemóvel';}" id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

<input onfocus="if (this.value == 'Email') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Email';}" value="Email" id="email" maxlength="80" name="email" size="20" type="text" /><br>

<input onfocus="if (this.value == 'Localidade') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Localidade';}" value="Localidade" maxlength="255" name="location" size="20" type="text" /><br>

.

And this is my contacto.php:

<?php
 // Get Data
 $name = strip_tags($_POST['name']);
 $email = strip_tags($_POST['email']);
 $phone = strip_tags($_POST['phone']);
 $location = strip_tags($_POST['location']);

 $headers .="De: Form thingy <examplealpha@someemail.com>";
 $headers .="CC: Mail1 <example1@someemail.com>";
 $headers .=", Mail2 <example2@someemail.com>";

 header("Location: thankyou.html");  //Redirect to Thank You HTML page after email is sent


 // Send message
 mail( "example1@someemail.com", "Formulário Facebook Av. Grátis",
 "Name: $name\nEmail: $email\nPhone: $phone\nLocation: $location\n",
  $headers );
 ?>
Veronica
  • 3
  • 3

2 Answers2

1

put the header location redirect after the send not before

// Send message
mail( "example1@someemail.com", "Formulário Facebook Av. Grátis",
 "Name: $name\nEmail: $email\nPhone: $phone\nLocation: $location\n",
 $headers );

 header("Location: thankyou.html");  //Redirect to Thank You HTML page after email is sent
Adidi
  • 5,097
  • 4
  • 23
  • 30
  • edited that bit just now, went back and filled in the form again but it didn't send any email. I may be missing some bit of code? – Veronica Mar 22 '13 at 21:24
  • Are you using your local environment ? or some server ? did your have php logs to some place ? – Adidi Mar 22 '13 at 21:27
  • I'm using my server. Should I use php logs? I don't know how to use them. Did it help if I linked here the URL to the form? – Veronica Mar 22 '13 at 21:31
  • the "mail" function return true/false - try to print that: $result = mail("exa.... - what is the result ? – Adidi Mar 22 '13 at 21:33
  • should I add mail("myemail@email.com", $subject, $text); to the php file to know that? – Veronica Mar 22 '13 at 21:40
  • just get the return value from the function and print it (echo it or something) – Adidi Mar 22 '13 at 21:45
  • sorry I don't know how to do that, I'm a php newbie. In either case thanks a lot for your help. This form is not sending any emails, I should learn php properly instead of hacking snippets of pho code together. – Veronica Mar 22 '13 at 21:57
  • This didn't work but I checked your answer in either case, thanks. – Veronica Mar 22 '13 at 22:13
1

Change:

$headers .="De: Form thingy <examplealpha@someemail.com>";

To:

$headers ="From: Form thingy <examplealpha@someemail.com>";

"De: is not standard as per PHP manual, use "From:....

http://php.net/manual/en/function.mail.php

http://php.net/manual/fr/function.mail.php

Full code:

<?php
// Get Data
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$location = strip_tags($_POST['location']);

$headers ="From: Form thingy <examplealpha@someemail.com>";
$headers .="CC: Mail1 <example1@someemail.com>";
$headers .=", Mail2 <example2@someemail.com>";

// Send message
mail( "example1@someemail.com", "Formulário Facebook Av. Grátis",
 "Name: $name\nEmail: $email\nPhone: $phone\nLocation: $location\n",
  $headers );

header("Location: thankyou.html");  //Redirect to Thank You HTML page after email is sent
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141