Jump to content

Archived

This topic is now archived and is closed to further replies.

tg11

email form hellp for novice

Recommended Posts

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

[code]<?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\">";
}
?> [/code]

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

[code]<?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\">";
}
?>[/code]

Share this post


Link to post
Share on other sites
pretty much, yes.
if they have further problems, then a line like:

[code]
ini_set("SMTP", "smtp.celebcars.co.uk");
[/code]

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

Share this post


Link to post
Share on other sites
thanks a lot, I'll give that a try, I know it was working flawlessly up until a couple of days ago.

Share this post


Link to post
Share on other sites

×

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.