Hello
How can I send an email by SMTP?
I need a PHP sample.
Please help me to get it.
Thank you
Printable View
Hello
How can I send an email by SMTP?
I need a PHP sample.
Please help me to get it.
Thank you
mail ($_POST['email'], 'subject of email here', 'body of email here', 'From: ur email here');
u have to make sure mail is enabled in the php ini file though
you should do more then that. As that will get rejected by some servers.
not the best but it works.PHP Code:$to = "[email protected]";
$subject = "You've won 1000$";
$message="This is a message."
#Headers############################################
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: person<[email protected]>' . "\r\n";
mail($to, $subject, $message, $headers);
But I want to use the SMTP of my website.
You can either change the values in your php.ini file
or you can set the values dynamicaly if you don't have access to you php.ini file.Code:[mail function]
; For Win32 only.
SMTP = localhost ; for Win32 only
smtp_port = 25
sendmail_from= [email protected] ; for Win32 only
The final method is to use sockets to connect manually to your SMTP server and send it that way, its the hardest is pointless as PHP already has built in support for sending emails, but if you want to use sockets them heres a link:PHP Code:ini_set("SMTP","localhost");
http://uk.php.net/sockets
The send email that is built into PHP doesn't support SMTP auth, just do a google search for 'SMTP auth PHP'.
Have you looked at:
http://phpmailer.sourceforge.net/
They say that it supports SMTP authentication but i haven't used it so im not sure if it fill definatly fit your needs.
I want a simple php example to send an email by used SMTP.
PHP Code:<?php
$to = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email][email protected][/email] . "\r\n" .
'Reply-To: [email]webmaster@example.com[/email]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
ini_set("SMTP","smtp.yoursite.com");
mail($to, $subject, $message, $headers);
?>
Irrelivant comments removed. Please don't Chit Chat in this forum.