Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/5405-email-form-hellp-for-novice/
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?
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]
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.