Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Email problem 1

Status
Not open for further replies.

EvolMonster

Programmer
Aug 14, 2006
41
0
0
GB
Hiya Guys!

I am developing a webpage for my friends business, and have hit a bit of a snag.

I want to set up a web page with a contact form. This is my test page with the form:


When the submit button (send to Cafe Fair Trade) is pressed I want the info from the form sent as an email to: enquiry@cafefairtrade.co.uk
then I want the page to forward to the this page:
This process requires a PHP script and I've configured a script from this website:

The script created I think is at:

It is working to a point. At the moment when the form is submitted an email is sent to: enquiry@cafefairtrade.co.uk
but an error message is also generated that is sent to: webmaster@cafefairtrade.co.uk
and I can't get the PHP to forward to:
The mail says :
The following error occurred in FormMail :
Unable to create check file "/tmp/fmc60c43.txt": failed to open stream: No such file or directory


Anyone got any ideas why this isn't working?
Cheers
DB
 
The immediate thing would be to check that there is indeed a directory called /tmp and that the script has the proper permissions for it.

I would wonder what that file is though - not used Formmail for many years.

The other thing is I would wonder why you are using Formmail.
PHP has a very easy to use email function. mail()

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
It does?
I'm new to PHP, so if you could provide an example on how to get mail() to do the same job, that would be great!!!
 
That looks excellent.
I will look at that later tonight. It looks really simple too!

Another thing. Would I be able to pass a variable in, containing which page the user clicked through to mail.

So if they click 'Contact Us' on the home page, I want to pass 'HomePage' through in the subject of the mail, etc.

Thanks!
DB
 
the requested page will be contained in the variable $_SERVER['REQUEST_URI']

you can test that and then create the subject of your email accordingly.
 
Brilliant!

I'll try that tonight.

Cheers guys, I'll get back to you if I can't make it work!
:)
 
Just be sure to look at the additional headers and additional parameters options else you may find that email sent gets blocked by anti-spam filters. This is especially important on shared servers.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Do they add alot of rubbish in them?

So i need to be setting them, even if I have no data to put in them?
 
I've had a thought.

What if I have several links on one page to send an email.

For example, 10 products on a pge, with Contact Us next to each.
If I want to know which one they clicked on (i.e. which product), and add that into the mail, is that possible?
 
yes. add a query parameter to the url in the link. the parameter will be in the $_GET superglobal.

eg

Code:
<a href="somepage.php?productID=354">Click Me for Info</a>

in your php the relevant information will be in $_GET['productID']

please create new threads for new issues in future.
 
Do they add alot of rubbish in them?

So i need to be setting them, even if I have no data to put in them?
No. But you can use them to ensure that the mail has the proper headers if the recipient's server does a reverse DNS lookup on the sender's domain.
In a shared environment the sender's domain will probably be different to the domain of the mail server.

So for instance, I would normally do something like this..

Code:
$to = someperson@somedomain.com;
$subject = "This is the message subject";
$message = "Hello World";

$headers = "From: sender@mydomain.com" . "\r\n" .
    "Reply-To: sender@mydomain.com" . "\r\n" .
    "X-Mailer: PHP/" . phpversion();
$params = "-fsender@mydomain.com";

// send the email
@mail($to,$subject,$message,$headers,$params);

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top