RieqyNS13 Posted May 16, 2013 Share Posted May 16, 2013 how do send html format with gmail smtp ? I just know some commands of smtp gmail to manage email they are MAIL FROM and RCPT TO. does it can be combined with mail($to, $sbj, $msg, $hdrs) ? Link to comment https://forums.phpfreaks.com/topic/278076-send-html-format-with-gmail-smtp/ Share on other sites More sharing options...
RieqyNS13 Posted May 16, 2013 Author Share Posted May 16, 2013 are this smtp commands is valid ? DATA From: "Edited Out" <[email protected]> To: "Edited Out" <[email protected]> Subject: Testing 4 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="boundary-type-1234567892-alt" --boundary-type-1234567890 --boundary-type-1234567892-alt Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Link to comment https://forums.phpfreaks.com/topic/278076-send-html-format-with-gmail-smtp/#findComment-1430503 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 The easiest way to achieve that is to use some php mail library as swiftmailer, phpMailer.... I'm a swiftmailer fan or you want to create everything from scratch? http://swiftmailer.org/docs/sending.html Link to comment https://forums.phpfreaks.com/topic/278076-send-html-format-with-gmail-smtp/#findComment-1430506 Share on other sites More sharing options...
RieqyNS13 Posted May 16, 2013 Author Share Posted May 16, 2013 I want to learn about manage the smtp with php. I have read some of PHPMail class, but there too many lines code. so, I decided to ask to this forum to learn step by step. do you know slices code of $mail->getFile('contents.html') in phpMailer class ? I have not founded it in class.smtp.php and class.phpmailer.php Link to comment https://forums.phpfreaks.com/topic/278076-send-html-format-with-gmail-smtp/#findComment-1430511 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 I don't have a previous attempt with phpMailer, so I will give you an example in swiftMailer. It's a pretty simple: <?php // include the library require_once 'lib/swift_required.php'; // Create the Transport $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465) ->setUsername('your username') ->setPassword('your password') ; // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); $subject = 'Wonderful Subject From SwiftMailer'; $body = '<p>Here is the message itself</p>'; // that's your html content $message = Swift_Message::newInstance() ->setContentType("text/html") ->setMaxLineLength(100) ->setSubject("' . $subject . '") ->setFrom(array("centos-box@localdomain" => "jazzman")) ->setBody($body); // Send the message $numSent = $mailer->send($message); printf("Sent %d messages\n", $numSent); Link to comment https://forums.phpfreaks.com/topic/278076-send-html-format-with-gmail-smtp/#findComment-1430521 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 Ops....I just forgot to add setTo() or if you prefer setBcc() methods. So the message should be something like: $message = Swift_Message::newInstance() ->setContentType("text/html") ->setMaxLineLength(100) ->setSubject($subject) ->setFrom(array("centos-box@localdomain" => "jazzman")) ->setTo(array('[email protected]', '[email protected]' => 'A name')) ->setBody($body); That's all. Link to comment https://forums.phpfreaks.com/topic/278076-send-html-format-with-gmail-smtp/#findComment-1430526 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 So, here is the test using my local CentOS machine. Check the status of sendmail client to be sure that we don't use it: [jazz@centos-box ~]$ su -c '/etc/init.d/sendmail status' Password: sendmail is stopped sm-client is stopped Now I will try to use my google account sending a message(s) to my yahoo mail account. <?php // include the library require_once 'Swift-5.0.0/lib/swift_required.php'; date_default_timezone_set('America/Toronto'); // Create the Transport $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl') ->setUsername('[email protected]') ->setPassword('myPassword') ; // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); $subject = 'Wonderful Subject From SwiftMailer'; $body = '<p>Here is the message itself</p>'; // that's your html content $message = Swift_Message::newInstance() ->setContentType("text/html") ->setMaxLineLength(100) ->setSubject($subject) ->setFrom(array("centos-box@localdomain" => "jazzman")) ->setTo(array('[email protected]' => 'jazzman')) ->setBody($body); // Send the message $numSent = $mailer->send($message); printf("Sent %d messages\n", $numSent); Result: from: jazzman <[email protected]>to: jazzman <[email protected]>date: Thu, May 16, 2013 at 4:42 PMsubject: Wonderful Subject From SwiftMailermailed-by: gmail.comsigned-by: gmail.com MIME-Version: 1.0Content-Type: text/html; charset=utf-8Content-Transfer-Encoding: quoted-printable<p>Here is the message itself</p> So, to use this method you don't have to have a mail server on the machine just we're using a remote mail server over ssl. Link to comment https://forums.phpfreaks.com/topic/278076-send-html-format-with-gmail-smtp/#findComment-1430542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.