Monday, 12 March 2007

Send email from PHP

Here is some sample code I came across over the net. It demonstrates two things:

One how to send email using PHP the second one is how to change the mail headers in order to send Unicode UTF-8 mail.

   $from = '';
   $to = '';
   $subject = 'Sending Unicode e-mail';
   $message = '
                This message contains and displays unicode characters like 
                the Greek Α, Γ and Ω
    $header = "Content-type: text/html; charset=utf-8\r\nFrom: $from\r\nReply-to: $from";
    if ( mail($to, $subject, $message, $header) ) 
        echo "Email sent to $to!";
        echo "Error occurred while sending email to $to!";


Remember that for the mail function to work correctly the SMTP Server must be correctly specified in PHP.ini.

I will come back with more precise info as soon as I have completed my tests

No comments :