Jump to content


Photo

email form hellp for novice


  • Please log in to reply
4 replies to this topic

#1 tg11

tg11
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 March 2006 - 09:17 AM

Hi all,

Im looking for some advice regarding my email form on a website I did for somebody. I received an email asking me to make som adjustments to it. This is the code I was originally using that worked fine

<?php 

// Website Contact Form Generator 
// [url]http://www.tele-pro.co.uk/scripts/contact_form/[/url] 
// This script is free to use as long as you    
// retain the credit link    
// get posted data into local variables 
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "enquiries@celebcars.co.uk"; 
$Subject = "information request"; 
$Name = Trim(stripslashes($_POST['Name'])); 
$subject = Trim(stripslashes($_POST['subject'])); 
$comments = Trim(stripslashes($_POST['comments'])); 

// validation 
$validationOK=true; 
if (Trim($EmailFrom)=="") $validationOK=false; 
if (Trim($Name)=="") $validationOK=false; 
if (Trim($subject)=="") $validationOK=false; 
if (Trim($comments)=="") $validationOK=false; 
if (!$validationOK) { 
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; 
  exit; 
} 

// prepare email body text 
$Body = ""; 
$Body .= "Name: "; 
$Body .= $Name; 
$Body .= "\n"; 
$Body .= "subject: "; 
$Body .= $subject; 
$Body .= "\n"; 
$Body .= "comments: "; 
$Body .= $comments; 
$Body .= "\n"; 

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); 

// redirect to success page 
if ($success){ 
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.htm\">"; 
} 
else{ 
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; 
} 
?>

but they said they updated their server and this is a fix here for it [a href=\"http://www.fasthosts.co.uk/knowledg.../?article_id=65\" target=\"_blank\"]http://www.fasthosts.co.uk/knowledg.../?article_id=65[/a]

do I just need to add this line they suggest - ini_set("sendmail_from", " email@mydomain ");

Im not sure where to add this to the code.

Hope somebody can help Im totally lost on this..

thanks in advance
Rob

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 March 2006 - 09:38 AM

I couldn't get the link you provided to work, but the code in question, ini_set, would go before the 'mail' function is called. i normally stick things like that right at the top of my page, after my includes and session_start().
the mail function's manual, ( [a href=\"http://uk.php.net/mail\" target=\"_blank\"]http://uk.php.net/mail[/a] ) will probably shed some light on what you want youre tryign to achieve, but when i change servers, normally the only setting i need to alter is 'SMTP' if i havent got a mail server set up on the same server as the php.
otherwise, i can't really see many reasons why the code you've posted still wouldnt work as it is.

did they give you any info in terms of the problem they were having?
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 tg11

tg11
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 March 2006 - 09:47 AM

thanks very much for replying.

What was on the link I sent was this

PHP on Windows
Use the PHP mail function and set the mail from using the following line of code - replacing email@mydomain with the correct domain name.


ini_set("sendmail_from", " email@mydomain ");

So I am assuming that all I would need to do was to add it to my code like this, Is this right?

thanks

<?php
ini_set("sendmail_from", " enquiries@celebcars.co.uk");

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "enquiries@celebcars.co.uk";
$Subject = "information request";
$Name = Trim(stripslashes($_POST['Name'])); 
$subject = Trim(stripslashes($_POST['subject'])); 
$comments = Trim(stripslashes($_POST['comments'])); 

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (Trim($subject)=="") $validationOK=false;
if (Trim($comments)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "subject: ";
$Body .= $subject;
$Body .= "\n";
$Body .= "comments: ";
$Body .= $comments;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>


#4 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 March 2006 - 09:53 AM

pretty much, yes.
if they have further problems, then a line like:

ini_set("SMTP", "smtp.celebcars.co.uk");

or whatever their outgoing mailserver is next to the other ini_set line should also help.

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#5 tg11

tg11
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 March 2006 - 10:07 AM

thanks a lot, I'll give that a try, I know it was working flawlessly up until a couple of days ago.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users