Page 1 of 1

Send mail using PHP

Posted: Tue Jul 17, 2007 11:23 pm
by dream2rule
This code does not work on localhost. I want to run it successfully on the local server even.

Can anyone help or guide me what do i do next?

Code: Select all

$to = "$email";
$subject = "Password Recovery";
	
$message = "<table width='65%' align='center' cellpadding='0' cellspacing='0' border='1'>
                      <tr><td>
  	              <table width='100%' align='center' border='0' cellpadding='0' cellspacing='0'>
    	              <tr>
      		          <td height='22' bgcolor='#990033'><span class='style1'></span></td>
    		      </tr>
    	              <tr>
      			<td height='29'><span class='style1'>&nbsp;&nbsp;Dear $row[1], </span></td>
    			</tr>
			<tr>
      			<td height='58'><span class='style1'>&nbsp;&nbsp;Thanks for registering with us. Your lost                                             password has been recovered. 
			 <p>Your details are as listed below: </p>
			 <p class='style1'>Username: $row[1]</p>
			 <p class='style1'>Password: $row[2]</p>
			 <p class='style1'>Hope you enjoy your stay with us!</p>
			 </span></td>
    			</tr>
    			 <tr>
      			 <td height='29'><span class='style1'>&nbsp;&nbsp;Thanks, </span></td>
    			 </tr>
    			 <tr>
      			 <td height='21'><span class='style1'>&nbsp;&nbsp;Administrator </span></td>
    			 </tr>
    			 <tr>
      			 <td height='21' bgcolor='#990033'>&nbsp;</td>
    			 </tr>
  		</table>
	</td></tr></table>";
		
        // To send HTML mail, the Content-type header must be set
		$headers = 'MIME-Version: 1.0' . "\r\n";
		$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
				
		$headers = "From: admin@something.com";
	
	      mail($to, $subject, $message, $headers);
		             exit("<br><font face=arial,verdana size=2><b>A mail has been sent to your email id. Thankyou!</b></font><br>");
Regards,
Dream2rule

Posted: Tue Jul 17, 2007 11:25 pm
by feyd
Does "localhost" have a mail server running? If not, you're going to need to alter some things. In fact, you may need to alter a lot of things.

To make it much easier, I'd suggest using Swiftmailer.

Posted: Tue Jul 17, 2007 11:35 pm
by dream2rule
From some help, i could gather a little information that i would need to add the POP3 and SMTP server details and also their port numbers.

How should i go about it??

Regards

Posted: Wed Jul 18, 2007 10:08 pm
by Phoenixheart
Normally you will have no smtp server pre-installed on your localhost, so your php mail functions won't execute. Try running them on a server that support php mailing.
Fot the mail settings, you may want to take a look at your php.ini file. If you can't access it (for example on a share hosting) try using ini_set().

Posted: Tue Jul 24, 2007 2:39 am
by dream2rule

Code: Select all

<?php

    require_once("htmlMimeMail5/htmlMimeMail5.php"); 

    // Instantiate a new HTML Mime Mail object
    $mail = new htmlMimeMail5();

    // Set the sender address
    $mail->setFrom("jason@example.com");//$from field
    
    // Set the reply-to address
    $mail->setReturnPath("jason@example.com");

    // Set the mail subject
    $mail->setSubject("Test HTML Mime Mail");

    // Set the mail body text
    $mail->setText("This is the body of the test email.");

    // Send the email!
    $mail->send(array("support@example.com"));//$to field

?>
The above code does not work even... :( :( :(

Can anyone help?

Regards