<?php
require_once "Mail.php";
$from = "<niko@gmail.com>";
$to = "<niko@hotmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<niko@gmail.com>";
$password = "somepassworrd";
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host,'port' => $port,'auth' =>true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail))
echo("<p>" . $mail->getMessage() . "</p>");
else
echo("<p>Message successfully sent!</p>");
?>
When I try to execute these php script I get these error
FATAL ERROR Class Mail NOT found ON number line 18
I know the above question is possible duplicate of these
Send email usi开发者_运维百科ng the GMail SMTP server from a PHP page
But its not working.My PHP version is 5.3.4 Xampp 1.7.4 version.
mail('caffeinated@example.com', 'My Subject', $message); \\ I tried these
But it shows a warning saying that missing headers.
How do I send an email Using the php script?
Can we send an email without using authentication in PHP ? Because vb.net uses server authentication but most of the code i found on google is without authentication for php. so I got a doubt
Finally please help me with these trying from an 2 hours or so!
The PHP mail() function is for sending mail via Sendmail. If you want to use some SMTP server, you can use Zend_Mail which makes this thing very easy: http://framework.zend.com/manual/en/zend.mail.html
Using Zend_Mail you only need to write something like this:
$config = array('auth' => 'login',
'username' => 'myusername',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('sender@test.com', 'Some Sender');
$mail->addTo('recipient@test.com', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send($transport);
The above handles authentication for you and sends a mail.
精彩评论