2010-08-07 6 views
2
<?php 
$to = "[email protected]"; 
$subject = "HTML email"; 
$message = " 
<html> 
<head> 
<title>HTML email</title> 
</head> 
<body> 
<p>This email contains HTML Tags!</p> 
<table> 
<tr> 
<th>Firstname</th> 
<th>Lastname</th> 
</tr> 
<tr> 
<td>John</td> 
<td>Doe</td> 
</tr> 
</table> 
</body> 
</html> 
"; 
// Always set content-type when sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 
// More headers 
$headers .= 'From: <[email protected]>' . "\r\n"; 
//$headers .= 'Cc: [email protected]' . "\r\n"; 
mail($to,$subject,$message,$headers); 
?> 

и мой файл php.ini являетсяКак отправить почту через localhost?

[mail function] 
; For Win32 only. 
; http://php.net/smtp 
SMTP = smtp.gmail.com 
; http://php.net/smtp-port 
smtp_port = 25 

; For Win32 only. 
; http://php.net/sendmail-from 
;sendmail_from = [email protected] 

плз предложить какое-либо решение, так что я буду иметь возможность отправлять почту с локального хоста

Благодарности

+0

, что mailserer вы работаете? – Nealv

ответ

5

Используйте функцию богатых SwiftMailer и ваши настройки должны быть такими:

username:google email addres 
password: your google password 
smtp: smtp.gmail.com 
port: 587 

Here is how you can set your credentials and send the email.

require_once 'lib/swift_required.php'; 

//Create the Transport 
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25) 
    ->setUsername('your username') 
    ->setPassword('your password'); 

//Sendmail 
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); 

//Create the Mailer using your created Transport 
$mailer = Swift_Mailer::newInstance($transport); 

//Create a message 
$message = Swift_Message::newInstance('Wonderful Subject') 
    ->setFrom(array('[email protected]' => 'John Doe')) 
    ->setTo(array('[email protected]', '[email protected]' => 'A name')) 
    ->setBody('Here is the message itself'); 

//Send the message 
$result = $mailer->send($message); 
0

Вы, кажется, использует неверный номер порта для smtp_port: при взгляде на GMail settings, похоже, вам потребуется порт 587 или 465. (В зависимости от того, хотите ли вы использовать шифрование TLS или SSL)

Кроме того, я не знаю, поддерживает ли PHP SSL и/или TLS. Если нет, вам нужно использовать дополнительную библиотеку PHP, чтобы иметь возможность подключения к почтовому серверу Google.

-2
  1. require_once 'lib/swift_required.php';

    //Create the Transport $transport = 
    Swift_SmtpTransport::newInstance('smtp.example.org', 25) 
    ->setUsername('your username') ->setPassword('your password'); 
    
    //Sendmail $transport = 
    Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); 
    
    //Create the Mailer using your created Transport $mailer = 
    Swift_Mailer::newInstance($transport); 
    
    //Create a message $message = Swift_Message::newInstance('Wonderful 
    Subject') ->setFrom(array('[email protected]' => 'John Doe')) 
    ->setTo(array('[email protected]', '[email protected]' => 'A name')) ->setBody('Here is the message itself'); 
    
    //Send the message $result = $mailer->send($message); 
    

    [1]: http://i.stack.imgur.com/t3Pbc.jpg

+1

Это, кажется, перефразировка ответа Сарфраза –

Смежные вопросы