2010-08-18 96 views

回答

0

PHP mailer将让你使用任何你喜欢的SMTP服务器,只要你有登录凭据。

2

您应该使用类似Swift MailerPHPMailer。下面的例子是斯威夫特:

$message = Swift_Message::newInstance() 
    ->setSubject('Your subject') 
    ->setFrom(array('[email protected]' => 'John Doe')) 
    ->setTo(array('[email protected]', '[email protected]' => 'A name')) 
    ->setBody('Here is the message itself') 
    ->addPart('<q>Here is the message itself</q>', 'text/html') 
; 

$transport = Swift_SmtpTransport::newInstance('smtp.mail.yahoo.com', 465, 'ssl') 
    ->setUsername('your username') 
    ->setPassword('your password') 
; 

$mailer = Swift_Mailer::newInstance($transport); 

$result = $mailer->send($message); 
2

您可以使用PHP的内置功能mail()发送邮件,但它通常是非常有限的。例如,我不认为你可以使用其他SMTP服务器,而不是你的php.ini文件中指定的服务器。

相反,你应该看看Mail PEAR package。例如:

<?php 
require_once "Mail.php"; 

$from = "Sandra Sender <[email protected]>"; 
$to = "Ramona Recipient <[email protected]>"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?"; 

$host = "mail.example.com"; 
$username = "smtp_username"; 
$password = "smtp_password"; 

$headers = array ('From' => $from, 
'To' => $to, 
'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
    '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>"); 
} 
?> 

(I偷http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm这个例子中:P)