Jump to content

Recommended Posts

are this smtp commands is valid ?

DATA
From: "Edited Out" <editedout@yahoo.com>
To: "Edited Out" <editedout@yahoo.com>
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


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

Edited by jazzman1

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 

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);

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('receiver@domain.org', 'other@domain.org' => 'A name'))
        ->setBody($body);

That's all.

Edited by jazzman1

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('accountName@gmail.com')
  ->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('myEmail@yahoo.com' => 'jazzman'))
        ->setBody($body);

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

printf("Sent %d messages\n", $numSent);

Result:

 

from:     jazzman <my_google_account@gmail.com>
to:         jazzman <my_yahoo_account@yahoo.com>
date:    Thu, May 16, 2013 at 4:42 PM
subject:  Wonderful Subject From SwiftMailer
mailed-by:     gmail.com
signed-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.

Edited by jazzman1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.