[Lancaster] Help needed with email from web pages

Ken Hough kenhough at uklinux.net
Thu Jun 28 17:56:11 BST 2007


jonath & Matt,

It seems that the lack of headers was the problem. I uploaded the
following code derived from link
'http://uk.php.net/manual/en/function.mail.php link::
<http://uk.php.net/manual/en/function.mail.php>

<?php
$to      = 'kenhough at uklinux.net';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: kenhough at uklinux.net' . "\r\n" .
    'Reply-To: kenhough at uklinux.net' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

?>

This did the trick  --  at least I was able to say 'hello' to myself.   ;-)

I'm fairly new to PHP and at first it was difficult to understand how to
use it. I've now got it to manage a 'photo gallery'. I like it. but it
can be hard work figuring out formatting for HTML strings to use in
building PHP functions.

Many thanks

Ken Hough

 wrote:
> Ken,
>
> Like Matt, I've always used the built-in mail function of php:
>
> http://uk.php.net/manual/en/function.mail.php
>
> The problem may be that you're not putting in the headers, but I
> appreciate these aren't absolutely necessary. A typical header might be:
>
> $headers = "From: Webmaster <webmaster at somewhere.co.uk\n";
> $headers .= "X-Sender: <webmaster at somewhere.co.uk
> <mailto:webmaster at somewhere.co.uk>>\n";
> $headers .= "X-Mailer: SMCPHP4.05(SG2001)\n";
> $headers .= "Return-Path: <postmaster at somewhere.co.uk
> <mailto:postmaster at somewhere.co.uk>>\n\r";
>
> [replace somewhere.co.uk <http://somewhere.co.uk> as appropriate]
>
> Also, bear in mind the following:
>
> 'Note: When sending mail, the mail must contain a From header. This
> can be set with the additional_headers parameter, or a default can be
> set in php.ini .
>
> Failing to do this will result in an error message similar to Warning:
> mail(): "sendmail_from" not set in php.ini or custom "From:" header
> missing. The From header sets also Return-Path under Windows.' [from
> the PHP web-site]
>
> So, given you were not using a header, PHP might have been checking
> php.ini for a valid 'from' address and maybe one did not exist there.
>
> Regards,
>
> Jonathan
>
>
> On 28/06/07, *Ken Hough* <kenhough at uklinux.net
> <mailto:kenhough at uklinux.net>> wrote:
>
>     Hi Guys!
>
>     Can you help me? I'm building a website and need to provide for
>     sending
>     email messages from within the site.
>
>     I been using PHP and for test/dev purposes run my own local webserver
>     (apache with mod_php). I know that the  web server and the PHP bit
>     work
>     OK, because the website uses PHP successfully for a number of
>     other tasks.
>
>     Using the very simple code:
>
>     <?php
>     // The message
>     $message = "Line 1\nLine 2\nLine 3";
>
>     // In case any of our lines are larger than 70 characters, we
>     should use
>     wordwrap()
>     $message = wordwrap($message, 70);
>
>     // Send
>     $x = mail('kenhough at uklinux.net <mailto:kenhough at uklinux.net>',
>     'My Subject', $message);
>
>     echo $message.'<br>';
>     if($x == TRUE) echo "TRUE".'<br>';
>     if($x == FALSE) echo "FALSE".'<br>';
>     ?>
>
>     appears to send a message  ---  at least judging by the LED
>     activity on
>     my ADSL /router, but no messages appear in my mail box and 'TRUE' is
>     echoed to the screen.
>
>     What am I missing?
>
>     Can annyone recomend a good Internet link on the subject?
>
>
>     Ken Hough
>
>     _______________________________________________
>     Lancaster mailing list
>     Lancaster at mailman.lug.org.uk <mailto:Lancaster at mailman.lug.org.uk>
>     https://mailman.lug.org.uk/mailman/listinfo/lancaster
>
>




More information about the Lancaster mailing list