Jump to content

Recommended Posts

Hi Every one,

 

First of, I hope I'm posting in the right section of the forum, if not please forgive me :)

 

My knowledge of phpp is poor/inexistant and thaks to some help I managed to create a script that send the info gathered throug a form in an email. That works fine.

 

At the end of the script, if everything was all right, the info was sent to an email, and the script, using the echo function was saying something like, thanks for enquiring with us...blah blah blah.

 

Now, for traffic monitoring purposes, instead of using a echo function, I wanted the script to open a new page (that would say the same.)

 

I found out the open header function is the one I need. I then replace the last line of my code with the above mentionned function, and starting testing it... and surprose it worked... well, almost!  ::)

 

Let me explain you what is wrong: 

 

the open header function does open a new page, but for some reason, the email is not sent anymore...

 

Could you please help me with that guys? Please find below the whole script. The only thing I changed is the last line, replacing echo by open header.

<?php
// La variable $verif, va nous permettre d'analyser si la sémantique de l'email est bonne
$verif="!^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-zA-Z]{2,4}$!";

// On assigne et protége nos variables
$email=$_POST["email"];
$from=htmlentities("From: ".$email);
$message=stripslashes(htmlentities('surname:  '.$_POST['surname']));
$message.="\n\n".'forename:   '.$_POST['forename']."\n\n";
$message.="\n\n".'email address:   '.$_POST['email']."\n\n";
$message.="\n\n".'Phone Number:   '.$_POST['phone']."\n\n";
$message.="\n\n".'want to be on mailing list?:   '.$_POST['info']."\n\n";
$message.="\n\n".'Where ?:     '.$_POST['origin']."\n\n";
$message.="\n\n".$_POST["message"]."\n\n";

// On met ici notre email
$destinataire="alex@sailnetuk.com";

/* On place le sujet du message qui ici sera toujours le même
puisque dans la partie Html on l'a mis en caché grace au type="hidden" avec comme valeur "Vous avez un nouveau message"  */
$objet='NEW NEILSON ENQUIRY - '.$_POST['what'];

// C'est bon on est OK, vérifions si l'email est valide, grâce à notre sympathique REGEX
if(!preg_match($verif,$email))
{
        echo "Your email address appears to be invalid, please check you entered it corectly.";
}

// On verifie si il y a un message
elseif (trim($message)=="")
{
        echo "Your message seems to be empty, please write a message, it will help us answering your enquiry";
}

// Si tout est OK on envoie l'email
else
{
        mail($destinataire,$objet,$message,$from);
       Header('Location: enquiries.php');
}


?>

 

the last line was before :

 echo "Your message has been succesfully sent! thank you for enquiring with us, we shall get back to you shortly"

 

Could you pleae tell me what is wrong, as it does open a new page, but does not send the email any more...

 

Many thanks in advance, and please forgive the funny sentences as, even though I am pretty fluent in english, it still is not my native language.

 

Cheers guys,

 

Lexa

 

Link to comment
https://forums.phpfreaks.com/topic/114646-form-mail-and-open-header/
Share on other sites

Yep, just did and found out it was html...

 

What you actually suggest is that I put a meta refresh in the header of my script, so then, when they get the echoed message, they could be redirected (maybe after half a second or so) towards a url I could track.

But I am not sure this would actually work as people are sent to the page mail.php (the page where the script quoted in the first post is), when the form is properly filled in, but also if there is a mistake (as in when they type in an invalid email address)

 

This why I wanted an alternative to echo for the actual confirmation of successful inquiry...

 

Did I get this right or where you suggesting using the refresh in another way?  :unsure:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.