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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending email

Status
Not open for further replies.

johk02

Programmer
Aug 20, 2003
169
AU
Hi,

I am new to PHP so this might be a silly question. I had this code to send email from a form on the website but all of a sudden it stopped working. If anyone could shed some light I would appriciated it.

Cheers

jonas
Code:
<?php

$frmname = "Name: $Name";
$frmemail = "Email: $email";
$frmphone = "Phone Number: $Phone";
$frmEnquiry = "Enquiry: \n $Enquiry";
$message = "$frmname \n$frmemail \n$frmphone \n$frmEnquiry";

$to = "info@site.com.au";

$from_header = 'From: info@site.com.au' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
   //send mail - $subject & $contents come from surfer input
   mail($to, $subject, $message , $from_header);
   // redirect back to url visitor came from
   header("Location: [URL unfurl="true"]http://www.site.com.au/contactthanks.html");[/URL]
?>
 
things typically do not "all of a sudden stop working". there will have been another intervening change. i advise investigating this.
 
all of a sudden it stopped working" is a little vague. What does not work? Do you get any error messages?

From the looks of it, I would say someone finally upgraded your php version and register globals is no longer turned on. Check the article on PHP.net to find out why turning off is smart and what to do about it.
 
Ok you are right - afer been talking to the host they mentioned that the PHp version had been upgraded.
This is the error msg I get:
Warning: Cannot modify header information - headers already sent by (output started at /var/ in /var/ on line 28

After some research I believe it means that only one header can be sent to minimize hacking attempts.
But in the above code there is only one header specified so I don't know what the problem is.

Thanks

jONAS
 
nope. that's not what it means. headers cannot be sent after any text is output to the browser. this can include even a single space. have a look in the faq to this forum for sleipnir's debugging faq.
 
From the code you entered, it appears that there is a line before the <?php. Try removing that and all other spaces like it and tell me what you get.

Matt
 
i finally got it sorted out. It was a combination of deleting the spaces and chaning the way I wrote my variables.
Thanks for your help.
Final code
Code:
<?php
$frmname = "Name: $_POST[Name]";
$frmemail = "Email: $_POST[email]";
$frmphone = "Phone Number: $_POST[Phone]";
$frmEnquiry = "Enquiry: \n $_POST[Enquiry]";
$message = "$frmname \n$frmemail \n$frmphone \n$frmEnquiry";
$to = "info@competencytraining.com.au";
$subject = "Enquiry From Website";
$from_header = 'From: info@competencytraining.com.au' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
   //send mail - $subject & $contents come from surfer input
   mail($to, $subject, $message , $from_header);
   // redirect back to url visitor came from
   header("Location: [URL unfurl="true"]http://www.competencytraining.com.au/contactthanks.html");[/URL]
?>
 
this is not correct
Code:
$frmname = "Name: $_POST[Name]";
although may work on some installations without throwing up warnings/notices

you should enquote your array keys where they are associative.

Code:
$frmname = "Name: [red]" . [/red] $_POST[[red]'[/red]Name[red]'[/red]];
 
Thanks for the tip.
I will change it.

Cheers
jonas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top