php htmlMimeMail5()

Posted on 2009-12-17
Last Modified: 2012-05-08

want to use

$mail = new htmlMimeMail5();
to send email

i am editing php but changing the email to gmail

is this being sent on port 587
i saw ehlo on telnet as a command
      $mail->setSMTPParams('', '587', 'EHLO', TRUE, '', 'password');

how does htmlmimemail5() differ from smtp

also do i have to use port 587
because i know that gmail uses port 465

function recordPHPerror($error_number, $error_string, $error_file, $error_line, $error_context) {

	$textbody = "



		Error Number: $error_number

		Error Message: $error_string

		Error Time: ".$_SERVER['REQUEST_TIME']."

		File: $error_file

		Line: $error_line

		Error Backtrace:

		".var_export(debug_backtrace(), true)."

		Error Context:

		".var_export($error_context, true)."</pre>";

	$htmlbody = $textbody;

	$mail = new htmlMimeMail5();


    $mail->setSubject("OW Error - ".md5($error_number.$error_string.$error_file.$error_line));




	$mail->setSMTPParams('', '587', 'EHLO', TRUE, '', 'password');

//	$mail->send(array(""),"smtp");

	return false;


Open in new window

Question by:rgb192
    LVL 40

    Accepted Solution

    There should be no need to change the parameters.

    You send to GMail using the same mechanism as any other SMTP server.

    I would use as the server and port 25 as normal.

    Port 587 is submission      587/tcp    Submission
    Port 465 is urd             465/tcp    URL Rendesvous Directory for SSM


    LVL 40

    Expert Comment

    Also, you've commented out the send() command, so maybe that's why it's not working!?
    LVL 40

    Expert Comment

    Edit the code below to use appropriate email addresses.
    // Prepare the email handler.
    $o_Mail = new htmlMimeMail5();
    $o_Mail->setText('You should not be able to read this message.\n\nIf you can, please contact your system administrator and ask for an email application capable of reading HTML/MIME Emails.');
     <title>GMail message using htmlMimeMail5.</title>
      <h1>GMail message using htmlMimeMail5.</h1>
      <hr />
    $o_Mail->setSubject('GMail message using htmlMimeMail5.');
    // Get the SMTP server for
    getmxrr('', $a_MXHosts, $a_Weights);
    // Sort the hosts so that the lowest weight server is first.
    $a_MXHosts = array_combine($a_MXHosts, $a_Weights);
    // Show the hosts.
    // Send email to each host until successful.
    $b_Sent = False;
    foreach($a_MXHosts as $s_Host => $i_Weight)
    	echo "Attempting to send to $s_Host with weight of $i_Weight", PHP_EOL;
    	if ($b_Sent = $o_Mail->send(array('"Richard Quadling" <>'), 'smtp'))
    // Did we send?
    if (!$b_Sent)
    	echo 'Failed to send email to any of the GMail hosts.';
    	exit (1);
    echo 'Successfully sent email to GMail.';

    Open in new window

    LVL 14

    Expert Comment

    LVL 40

    Expert Comment

    Profya, thanks for the link. specifically.

    More or less repeating what I said already.

    The only real change is that getmxrr() is now available on Windows in PHP (it wasn't when I write the answer back in March 2007).


    Author Closing Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now