Email from PHP

In the PHP.ini file I have the following code:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = the_test.email@gmail.com <=== sending email address

Is this correct?

Thanks

When a line begins with a semi-colon, what follows is treated as a comment.
So if you are “Win32 only”, you may want to remove the leading semi-colon.

you want to send email ?
use function mail

Hi

the best option is to use the well known email class PHPMAILER, you just need to put a 5 lines code and it will do the rest. Just Google It.

Regards

I now have the following error:

Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\email_test.php on line 13

[COLOR=“Red”]php.ini file looks likes this:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com
sendmail_from = the_test.email@txt.att.net ;jdg 09-17-2008<=== sending email address which is my wireless connection email address (wireless is running)
[/COLOR]
[COLOR=“Blue”]PHP program:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<title>Just another Test</title>
</head>
<body>
<?php

mail("jperson19468@gmail.com", “This is email test”,
“This is the great email test if this works on ward to next part of the test”,
“From: the_test.email@txt.att.net”);
echo “Complete”;

?>

</body>
</html> [/COLOR]

Is the dll line uncommented? In the php.ini section

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

you should see

;extension=php_smtp.dll

Try uncommenting that. And make sure you have the php_smtp.dll file too.

I don’t seem to have the line ;extension=php_smtp.dll in my PHP.ini file.
And I can’t fine php_smtp.dll file on the system

Jerome

It seems odd that the php.ini file would have SMTP = localhost and smtp_post = 25 and not have the php_smtp.dll module. I’m far from being an installation guru, but maybe you can get the dll and add the line to the list of extensions and it will work?

I’ll PM you a temp link to a copy of what I have.

SMTP = localhost
at this line you must change localhost for your ISP smtp name server

Where would I fine my ISP’s smtp name server name at? I use a wireless connection from AT&T.

Thanks

I have download the php_smtp.dll file and have put it into the C:\PHP directory.
I have also inserted the line extension=php_smtp.dll into the php.ini file. I have the line as the last line under the Windows Extensions section with all of the other extensions. Part of the code looks like this:
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll
extension=php_smtp.dll

Are there other DLL files in the C:\PHP directory? In my set up they’re in the C:\xampplite\php\ext folder.

Check the php.ini file under

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

for somethibng like

; Directory in which the loadable extensions (modules) reside.
extension_dir = "\\xampplite\\php\\ext\\"

that’s where it should go.

This is what my php.ini file looks like under extension section:

Directory in which the loadable extensions (modules) reside.
extension_dir = “c:\PHP\ext”
extension=php_mysql.dll
extension=php_mysqli.dll

I moved the php_smtp.dll to the “c:\PHP\ext” directory

I also believe my ISP’s smtp name server name is cwmx.com.

So this line should now read: SMTP = cwmx.com Correct?

Thanks

You lost me there. You are trying to run PHP on your computer, but use your online host server’s SMTP? Sorry, but I usually have at least some trouble with installations as it is, and although I have managed to learn how to do some things, I don’t know how to do that. But I will try to find out. My WAMP server used a local Mercury mail server but obviously with xampplite it isn’t so easy, I just uncommented the line in my php.ini file and ran a test mail() script and got

Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\xampplite\htdocs\sendit.php on line 8

EDIT: According to this

Change SMTP to your ISP’s server and sendmail_from to your email address on the mail server.

I have several email addresses. I tried using my site’s email server. I had to change localhost to mail.mydomain.com, and port 25 to port 587 for the connection to work. But then I got a “denied” error. It seems it needs authentication. As the native PHP mail function doesn’t provide for this, I downloaded the PEAR Mail, Net_SMTP, and Net_Socket packages. I’ll try tomorrow and post back.

I finally managed to get it to send an email from my localhost using my remote mail server. I used a slightly modified version of the code I found here http://email.about.com/od/emailprogrammingtips/qt/et073006.htm

<?php
require_once "Mail.php";

$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\
\
How are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

But I had to use an “ini_set(ini_get” to add the path to the PEAR packages and add "‘port’ => 587, " to the factory array.

$from doesn’t seem to matter as long as it’s “email address format, @.*”
$to should be to your recipient of choice
$host should be your remote mail server
$username in my case was one of my site’s valid email account address
$password was the password I use to log in to the account

Do I have to use pear?

I used it because the remote SMTP mail server I used requires authentication, and the natiive PHP mail function doesn’t have that capability. I used PEAR because I’m familiar with using PEAR, but AFAIK there are other libraries that send authentication too.

Let me contact my ISP to get some information