Jump to content

Recommended Posts

hey guys i'm trying to test and send a email via SMTP...now i'm able to connect to server and auth login which is fine...but im having a problem sending the email using this line...everything else returns ok from the server.

 

problem is on this line:

fputs($this->_smtp_connection, "To: ricky.powell@hotmail.co.uk, destramic@gmail.com\nFrom: noreply@bisi.bis\nSubject: hello\n$headers\n\n$message\n\n");

when using this code the server times out displaying error 500...i've tried to look if the command im using is correct and from what i can see on a tutorial it checks out.

 

 

the code im using after connect and auth

  fputs($this->_smtp_connection, "MAIL FROM: noreply@bisi.bid" . $this->_CRLF);
      print_r($this->get_response());
        fputs($this->_smtp_connection, "RCPT TO: ricky.powell@hotmail.co.uk" . $this->_CRLF);
        fputs($this->_smtp_connection, "RCPT TO: destramic@gmail.com" . $this->_CRLF);
        print_r($this->get_response());
        
        fputs($this->_smtp_connection, "DATA" . $this->_CRLF);
        print_r($this->get_response());
        
        $headers = "MIME-Version: 1.0" . $this->_CRLF;
        $headers .= "Content-type: text/html; charset=iso-8859-1" . $this->_CRLF;
        $headers .= "To: Ricky Powell <ricky.powell@hotmail.co.uk>" . $this->_CRLF;
        $headers .= "To: Ricky Powell <destramic@>gmail.com" . $this->_CRLF;
        $headers .= "From: noreply@bisi.bid <bisi.bid>" . $this->_CRLF; 
        $message = "hello ricky.";

       //fputs($this->_smtp_connection, "To: ricky.powell@hotmail.co.uk, destramic@gmail.com\nFrom: noreply@bisi.bis\nSubject: hello\n$headers\n\n$message\n\n");
       // print_r($this->get_response());

any help would be greatful...thank guys

 

Link to comment
https://forums.phpfreaks.com/topic/295856-smtp-command-problems/
Share on other sites

i have been using \r\n on the other commands but the tutorial just used \n on that part so i assumed it was right...but after changing it i got the ok message :)...so thank you

 

 

Array (

 => 250 [message] => 2.1.0 Ok )

 

but...i haven't received nothing in either of my inbox's...and ideas to why it would say ok but why i would get no email?

 

 

As a side note, you should be including a strlen in the fputs function, or it could be corrupted.

 

thanks for the tip...i would do this on every fputs execution right?

 

thanks again

Edited by Destramic

i got working now...i didnt add the DOT at the end of the message :suicide:

 

now that being done can i just ask a few questions please...

 

1. how do i add a body and a altbody?...for instance if the recipient doesn't support HTML emails i just just send alt-body.

 

2. what the difference between connection normally to the server to connecting using telnet? ie.

fsockopen($host . ":" . $port, $error_number, $error_string, $timeout);

vs

fsockopen('telnet ' . $host . ' ' . $port);

thank you

ok well i found out i needed to set the content type to multipart/alternative with boundaries

 

some  reason its not sending to my inbox...can anyone please tell me why?

$boundary = uniqid('email');
$command = "MIME-Version: 1.0" . $this->_CRLF;
$command .= "To: Ricky Powell <ricky.powell@hotmail.co.uk>" . $this->_CRLF;
$command .= "From: BiSi.bid <noreply@bisi.bid>" . $this->_CRLF;
$command .= "Subject: hello" . $this->_CRLF;

$command .= "Content-Type: multipart/alternative; boundary=$boundary". $this->_CRLF;
$command .= "Content-type: text/plain; charset=iso-8859-1" . $this->_CRLF;
$command .= "Content-Transfer-Encoding: quoted-printable" . $this->_CRLF;

$command .= "This is a MIME encoded message" . $this->_CRLF;

$command .= "-- " . $boundary . $this->_CRLF;

$command .= "plain text" . $this->_CRLF;


$command .= "-- " . $boundary . $this->_CRLF;

$command .= "Content-type: text/html; charset=iso-8859-1" . $this->_CRLF;
$command .= "Content-Transfer-Encoding: quoted-printable" . $this->_CRLF;
$command .= "<b>html text</b>" . $this->_CRLF;
$command .=  $this->_CRLF . "--" . $boundary . "--" . $this->_CRLF;

$this->send_command($command);

$this->send_command('.' . $this->_CRLF);
print_r($this->get_response());

thank you

    $command = "From: BiSi.bid <noreply@bisi.bid>" . $this->_CRLF;
    $command .= "To: Ricky Powell <ricky.powell@hotmail.co.uk>" . $this->_CRLF;
    
    
    $command .= "Subject: hello" . $this->_CRLF;
    
    $command .= "MIME-Version: 1.0" . $this->_CRLF;
    $command .= "Content-Type: multipart/alternative; boundary=" . $boundary . $this->_CRLF;
    $command .= "Content-Transfer-Encoding: 7bit" .$this->_CRLF;
    
    $command .= "--" . $boundary . $this->_CRLF;
    $command .= "Content-type: text/plain; charset=iso-8859-1" . $this->_CRLF;
    $command .= "Content-Transfer-Encoding: 7bit" . $this->_CRLF;
    $command .= "Content-Transfer-Encoding: quoted-printable" . $this->_CRLF;
    $command .= "plain text" . $this->_CRLF;
    $command .= "-- " . $boundary . $this->_CRLF;
    
    $command .= "Content-type: text/html; charset=iso-8859-1" . $this->_CRLF;
    $command .= "Content-Transfer-Encoding: 7bit" . $this->_CRLF;
    $command .= "Content-Transfer-Encoding: quoted-printable" . $this->_CRLF;
    $command .= "<b>hello</b>" . $this->_CRLF;
    $command .= "--" . $boundary . "--" . $this->_CRLF;
    
    $this->send_command($command . '.' . $this->_CRLF);
     
    print_r($this->get_response()); 

after playing with the code i not get the email in my inbox but the message is empty...any ideas why?

Email is a tricky thing, as it has a lot to do with white list, black list an so on.  If you are on a shared server, the server could be blacklisted.  Some servers also require the FROM address to be an address active on the server.  I normally suggest that people use phpmailer, as they make it somewhat easier.

The confusing part with your thread is that you have moved to a different set up, and/or you aren't giving enough info.

Bottom line, using a mailing library like PHPMailer, SwiftMailer, Zend_Mail, eZcomponents etc. would have you already up and running.

The confusing part with your thread is that you have moved to a different set up, and/or you aren't giving enough info.

 

yeah im not trying to send a multipart email plain text and html =/...basically if i just sent a plain or email without it being multipart it sends perfectly

 

I normally suggest that people use phpmailer, as they make it somewhat easier.

 

i'm not a fan of using script other people have used...i like to break something down and write it myself...but i can't workout for the life of me why the message is blank

Yes, but there are standards for valid emails. This seems to be lost on most people. There is no such thing as html emails -- there are text emails with attachments which can include an html portion as an option. It is up to the email client to handle the email.

 

Just because the majority of email clients will handle an html email doesn't mean it's proper to just send html. Furthermore, it's a bad idea because security paranoid people will have configured their email to disable any html and your emails will never be seen.

 

This is why the only proper and 100% valid emails that want to include html need to be multipart. It's more complicated, but as pointed out, it's also a problem solved for a long time and formalized in any of the many libraries you were already pointed to.

 

Otherwise --- you really need to figure out some ways to debug it, including writing the output to a file so you can look at it by hand, or possibly turning on settings in your MTA that will give you some information.

  • 2 weeks later...

i sorted the problem out now...these headers will send a multipart email plain and html depending on users mail settings.

 

heres the headers

//$this->_CRLF = \n which depends on OS

$boundary = md5(time());
$headers = "From: name here <noreply@example.bid>" . $this->_CRLF;
$headers .= "To: my name <example@example.com>" . $this->_CRLF;
$headers .= "Subject: hello" . $this->_CRLF;
$headers .= "MIME-Version: 1.0" . $this->_CRLF;

$headers .= "Content-Type: multipart/alternative; boundary=" . $boundary . $this->_CRLF;
$headers .= "This is a multi-part message in MIME format" . $this->_CRLF;

$headers .= "--" . $boundary . $this->_CRLF;
$headers .= "Content-type: text/plain; charset=iso-8859-1" . $this->_CRLF;
$headers .= "hello, plain text" . $this->_CRLF.  $this->_CRLF;
        
$headers .= "--" . $boundary . $this->_CRLF;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $this->_CRLF;
$headers .= "<b>hello</b>" . $this->_CRLF;
$headers .= "--" . $boundary . "--" . $this->_CRLF;

$this->send_command($headers . '.' . $this->_CRLF);

thanks for your help guys

Edited by Destramic
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.