2011-01-30 14 views
0

phpとgmailを使って電子メールを送信する最も良い方法は何ですか?phpとgmailを使って電子メールを送信する最も良い方法は何ですか?

iはリンクの下の目が見つかりました:

sending mail with PHPMailer

をしかし、それはサイトのダウンロードphpmailerのは、形成した後、私はclass.phpmailer.phpを見つけることができませんでした!

私はメール(GmailサーバーとPHP LAN)を送信する方法を教えてくれますか?

別の質問は、私のGmailアカウントがsmtpに設定されている/それは大丈夫ですか?

よろしく

+0

Uは、SSL /ポート/ htmlの体としてのすべての機能をphpmailerのを使用せずに、私の完全なコードを表示することができます... – LostLord

+0

はで同様のSO質問をチェックアウトすることもできます:http://stackoverflow.com/questions/36079/php-mail-using-gmail – used2could

答えて

2

私はあなたがSMTPサーバとしてsmtp.gmail.comを指定し、SSLを使用するように指定してSmtpTransport、とSwiftMailerを使用することをお勧め。

Example

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com') 
    ->setPort(465) 
    ->setEncryption('ssl') 
    ->setUsername('[email protected]') 
    ->setPassword('YOUR_SECRET_PWD'); 
... 

編集、 要求されるように - ここに完全な例は、(ただし、未テスト)です:

<?php 
require_once "lib/swift_required.php"; 

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com') 
    ->setPort(465) 
    ->setEncryption('ssl') 
    ->setUsername('[email protected]') 
    ->setPassword('YOUR_SECRET_PWD'); 

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

$htmlBody = '<html><body><h1>HTML-mail example!</h1><p>Contents</p></body></html>'; 
$plainBody = 'Looks like you cannot read HTML-emails? This is alternative content only for you.'; 

$message = Swift_Message::newInstance('This is the subject of the e-mail') 
    ->setFrom(array('[email protected]' => 'You Name')) 
    ->setTo(array('[email protected]' => 'Your Friends Name')) 
    ->setBody($plainBody) 
    ->addPart($htmlBody, 'text/html'); 

$mailer->send($message); 
+0

woul u plz私にphpmailerまたは簡単な方法を教えてください! /私は無料のホストでそれをテストしたいので、それはSwiftMailerのサイズが高いと思われるので... – LostLord

+0

phpmailerのサイトに/なぜドキュメントはありません?どのように私はそれのプロジェクトを使用することができますか? – LostLord

+0

私はちょうどメールを(gmailで)送信したい/それを行うための完全なコードの私のためのPLZを書くだろうか? – LostLord

関連する問題