SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 25
Thread: Email Problem
-
Sep 7, 2005, 08:52 #1
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Email Problem
Hi all,
Why won't this send an email. SMTP is running.
PHP Code:$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: Training Department\n";
$subject = ucwords('hello');
$content = "From: ".ucwords($name)."\n"
."Message: \n Hi all \n"
.$note."Regards, \n"
.ucwords($name);
foreach ($email as $key => $value)
{
$value .= '@yahoo.com';
echo $key .'=>'. $value.'<br />';
mail($value, $subject, $content, $headers);
}
-
Sep 7, 2005, 09:16 #2
- Join Date
- Dec 2004
- Location
- Over the hill and through the woods...
- Posts
- 306
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$value should be who the email is to, not from. The first thing in a mail syntax is always the recepients email.
-
Sep 7, 2005, 09:20 #3
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes. I know that. $value is who the email should be sent to.
-
Sep 7, 2005, 10:19 #4
What trouble are you having? Sends ok for me!
-
Sep 8, 2005, 01:29 #5
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It doesn't seem to send the email.
Here's my php.ini settings:
PHP Code:; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
sendmail_from = me@mysite.com
-
Sep 8, 2005, 02:04 #6
Have you ever managed to send mail through this server? Obviously the webserver and mailserver are running on the same machine, right?
-
Sep 8, 2005, 02:27 #7
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The webserver is on this machine.
For the mail server all I did was get the SMTP service running on the same computer. (Using Windows)
Anything else I should have done?
-
Sep 8, 2005, 15:36 #8
Have you solved this yet? If not I have a solution.
-
Sep 8, 2005, 15:43 #9
- Join Date
- Aug 2004
- Location
- Chicago
- Posts
- 296
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Check your isp, and see if they disable port 25. (Mine does, so I can't send mail)
Why's (Poignant) Guide to Ruby
learn ruby with foxes, wizards, and chunky bacon
-
Sep 8, 2005, 15:56 #10
- Join Date
- Mar 2005
- Posts
- 0
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Or check your SMTP log to see if at least he try to send the email, even if the ISP block port 25 the SMTP on localhost should log the attempt to send the email
-
Sep 8, 2005, 16:07 #11
- Join Date
- Sep 2005
- Location
- Sydney, Australia
- Posts
- 776
- Mentioned
- 11 Post(s)
- Tagged
- 0 Thread(s)
You might want to try and check the logs of your SMTP server.
At home I use 'PostCast Server' - a free SMTP server for windows to test mail scripts. (http://www.postcastserver.com).
It has to option to only 'manually' send the mail (so you have the chance to open up the admin program and see what mails are waiting to get sent out).
I would also suggest you try:
PHP Code:<?php
$date = date('Y-h-d H:i:s');
if (mail('sometest@account.com', 'Test', 'This is a test mail - at ' . $date)) {
print 'Mail was sent...';
}
else {
print 'Mail was not sent - check any error output that might be printed.';
}
?>
Hope this helps ...var details = {
. . web: "afterlight.com.au",
. . photos: "jvdl.id.au",
. . psa: "usethelatestversion.com"
}
-
Sep 8, 2005, 23:32 #12
Of course it's not working. He is not sending authentication, which on a windows server is impossible with mail(). There are only two choices: 1) configure the mailserver not to require authentication from localhost or 2) use fsockopen and send authentication. I have written a function that does number 2 and there is also php mailer or the pear module.
So if you want to be able to use mail() only option is configure the mailserver to allow it.
-
Sep 9, 2005, 01:25 #13
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi bokehman. How do I configure the mailserver? or how do I use option 2? fsockopen and authentication?
Thanks.
Kevin.
-
Sep 9, 2005, 01:46 #14
Option 2.
Change your mail() command to win_mail and then put the function I am posting at the bottom of your script or in an external file and require() it. Don't forget to fill in your username and pasword in the first line of the function. Tell me how you get on.
PHP Code:<?php
function win_mail($to, $subject, $message, $headers = NULL, $username = 'your username here', $password = 'your password here', $mailserver = NULL)
{
function error($error, $connect = NULL)
{
if(isset($_GET['debug']))print $error; // comment this out once you get the script working
if(!empty($connect)){
fputs($connect,"QUIT\r\n");
fclose($connect);
}
return FALSE;
} // end function error()
if(isset($headers)){
foreach(explode("\n", $headers) as $v){
if(eregi('from:', $v) and eregi('@', $v)){
$from = TRUE;
$mail_from = $v;
if(preg_match('/<(.+?)>/', $mail_from, $match)){
$mail_from = $match['1'];
}else{
$mail_from = trim(trim(strstr($mail_from, ':'), ':'));
}
}
}
}
if(empty($mail_from)) $mail_from = ini_get('sendmail_from');
if(empty($mail_from)) $mail_from ='php-mailer@'.$_SERVER['HTTP_HOST'];
if(empty($from)) {$from = "From: $mail_from\n";}else{$from = NULL;}
if(empty($headers))$headers = '';
$message = "Date: ".date('D, d M Y H:i:s O')."\n".$from."To: ".$to."\nSubject: ".$subject."\n".$headers."\n\n".$message;
if(!isset($mailserver))$mailserver = ini_get('SMTP');
if(!$connect = @fsockopen($mailserver, 25, $errno, $errstr, 5)) return(error('Could not connect to mail server'));
stream_set_timeout($connect, 10);
if (!ereg("^220", fgets($connect, 1024)))return(error('No 220', $connect));
fputs ($connect, "EHLO [127.0.0.1]\r\n");
$out = fgets ( $connect, 1024 );
while(!ereg('^250', $out)&&(!empty($out))){
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 5);
}
for($tries = 15; $tries > 0; $tries--){
if(ereg('^250', $out)){
if(eregi('AUTH=LOGIN|AUTH LOGIN', $out))$auth_login = TRUE;
$for_loop_hop = $out;
}elseif(empty($out)){
usleep(100000);
}
stream_set_timeout($connect, 0, 5000);
$out = fgets($connect, 1024);
stream_set_timeout($connect, 5);
}
if(!ereg('^250', $for_loop_hop))return(error('No 250', $connect));
if(!isset($auth_login))return(error('No AUTH LOGIN'));
fputs ($connect, "AUTH LOGIN\r\n");
if (!ereg("^334", fgets($connect, 1024)))return(error('No 334 (username)', $connect));
fputs ($connect, base64_encode($username)."\r\n");
if (!ereg("^334", fgets($connect, 1024)))return(error('No 334 (password)', $connect));
fputs ($connect, base64_encode($password)."\r\n");
if (!ereg("^235", fgets($connect, 1024)))return(error('No 235 (not authenticated)', $connect));
fputs ($connect, "MAIL FROM: <{$mail_from}>\r\n");
if (!ereg("^250", fgets($connect, 1024)))return(error('No 250 (after MAIL FROM:)', $connect));
fputs ($connect, "RCPT TO: <{$to}>\r\n");
if (!ereg("^250", fgets($connect, 1024)))return(error('No 250 (after RCPT TO:)', $connect));
fputs($connect,"DATA\r\n");
stream_set_timeout($connect,20);
if (!ereg("^354", fgets($connect,512)))return(error('No 354 (Enter mail)', $connect));
fputs($connect, "$message\r\n.\r\n");
if (!ereg("^250", fgets($connect,512)))return(error('No 250 (End of mail)', $connect));
fputs($connect,"QUIT\r\n");
fclose($connect);
return TRUE;
}
?>
-
Sep 9, 2005, 06:32 #15
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi Bokehman. No luck yet. I must have a semi-colon or ' missing somewhere as all I get is a blank page...
Any ideas?
PHP Code:<?php
$to = 'myname@yahoo.ie';
$message = 'hello';
$subject = 'News';
win_mail($to, $subject, $message, $headers);
function win_mail($to, $subject, $message, $headers = NULL, $username = 'uname', $password = 'pword', $mailserver = NULL)
{
function error($error, $connect = NULL)
{
if(isset($_GET['debug']))print $error; // comment this out once you get the script working
if(!empty($connect)){
fputs($connect,"QUIT\r\n");
fclose($connect);
}
return FALSE;
} // end function error()
if(isset($headers)){
foreach(explode("\n", $headers) as $v){
if(eregi('from:', $v) and eregi('@', $v)){
$from = TRUE;
$mail_from = $v;
if(preg_match('/<(.+?)>/', $mail_from, $match)){
$mail_from = $match['1'];
}else{
$mail_from = trim(trim(strstr($mail_from, ':'), ':'));
}
}
}
}
if(empty($mail_from)) $mail_from = ini_get('sendmail_from');
if(empty($mail_from)) $mail_from ='php-mailer@'.$_SERVER['HTTP_HOST'];
if(empty($from)) {$from = "From: $mail_from\n";}else{$from = NULL;}
if(empty($headers))$headers = '';
$message = "Date: ".date('D, d M Y H:i:s O')."\n".$from."To: ".$to."\nSubject: ".$subject."\n".$headers."\n\n".$message;
if(!isset($mailserver))$mailserver = ini_get('SMTP');
if(!$connect = @fsockopen($mailserver, 25, $errno, $errstr, 5)) return(error('Could not connect to mail server'));
stream_set_timeout($connect, 10);
if (!ereg("^220", fgets($connect, 1024)))return(error('No 220', $connect));
fputs ($connect, "EHLO [127.0.0.1]\r\n");
$out = fgets ( $connect, 1024 );
while(!ereg('^250', $out)&&(!empty($out)))
{
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 5);
}
for($tries = 15; $tries > 0; $tries--)
{
if(ereg('^250', $out))
{
if(eregi('AUTH=LOGIN|AUTH LOGIN', $out))$auth_login = TRUE;
$for_loop_hop = $out;
}elseif(empty($out))
{
usleep(100000);
}
stream_set_timeout($connect, 0, 5000);
$out = fgets($connect, 1024);
stream_set_timeout($connect, 5);
}
if(!ereg('^250', $for_loop_hop))return(error('No 250', $connect));
if(!isset($auth_login))return(error('No AUTH LOGIN'));
fputs ($connect, "AUTH LOGIN\r\n");
if (!ereg("^334", fgets($connect, 1024)))return(error('No 334 (username)', $connect));
fputs ($connect, base64_encode($username)."\r\n");
if (!ereg("^334", fgets($connect, 1024)))return(error('No 334 (password)', $connect));
fputs ($connect, base64_encode($password)."\r\n");
if (!ereg("^235", fgets($connect, 1024)))return(error('No 235 (not authenticated)', $connect));
fputs ($connect, "MAIL FROM: <{$mail_from}>\r\n");
if (!ereg("^250", fgets($connect, 1024)))return(error('No 250 (after MAIL FROM:)', $connect));
fputs ($connect, "RCPT TO: <{$to}>\r\n");
if (!ereg("^250", fgets($connect, 1024)))return(error('No 250 (after RCPT TO:)', $connect));
fputs($connect,"DATA\r\n");
stream_set_timeout($connect,20);
if (!ereg("^354", fgets($connect,512)))return(error('No 354 (Enter mail)', $connect));
fputs($connect, "$message\r\n.\r\n");
if (!ereg("^250", fgets($connect,512)))return(error('No 250 (End of mail)', $connect));
fputs($connect,"QUIT\r\n");
fclose($connect);
return TRUE;
}
?>
-
Sep 9, 2005, 06:52 #16
Originally Posted by obrienkev
PHP Code:$to = 'myname@yahoo.ie';
$message = 'hello';
$subject = 'News';
if(win_mail($to, $subject, $message)){
echo 'mail sent';
}else{
echo 'mail not sent';
}
-
Sep 9, 2005, 07:02 #17
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bokehman, it still doesn't return anything. Just blank page. And tried adding ?debug but same story.
-
Sep 9, 2005, 07:11 #18
put this at the top:
PHP Code:ini_set('display_errors', '1');
error_reporting(E_ALL);
-
Sep 9, 2005, 08:11 #19
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Found missing } at end of else clause.
Now it displays 'mail not sent'Last edited by obrienkev; Sep 9, 2005 at 08:13. Reason: syntax error found
-
Sep 9, 2005, 08:15 #20
Change the function to the following and use ?debug at the end of your URL so it prints the error the mailserver returns.
PHP Code:function win_mail($to, $subject, $message, $headers = NULL, $username = 'user', $password = 'pass', $mailserver = NULL)
{
function error($error, $connect = NULL)
{
if(isset($_GET['debug']))print $error; // comment this out once you get the script working
if(!empty($connect)){
fputs($connect,"QUIT\r\n");
fclose($connect);
}
return FALSE;
} // end function error()
if(isset($headers)){
foreach(explode("\n", $headers) as $v){
if(eregi('from:', $v) and eregi('@', $v)){
$from = TRUE;
$mail_from = $v;
if(preg_match('/<(.+?)>/', $mail_from, $match)){
$mail_from = $match['1'];
}else{
$mail_from = trim(trim(strstr($mail_from, ':'), ':'));
}
}
}
}
if(empty($mail_from)) $mail_from = ini_get('sendmail_from');
if(empty($mail_from)) $mail_from ='php-mailer@'.$_SERVER['HTTP_HOST'];
if(empty($from)) {$from = "From: $mail_from\n";}else{$from = NULL;}
if(empty($headers))$headers = '';
$message = "Date: ".date('D, d M Y H:i:s O')."\n".$from."To: ".$to."\nSubject: ".$subject."\n".$headers."\n\n".$message;
if(!isset($mailserver))$mailserver = ini_get('SMTP');
if(!$connect = @fsockopen($mailserver, 25, $errno, $errstr, 5)) return(error('Could not connect to mail server'));
stream_set_timeout($connect, 10);
if (!ereg("^220", fgets($connect, 1024)))return(error('No 220', $connect));
fputs ($connect, "EHLO [127.0.0.1]\r\n");
$out = fgets ( $connect, 1024 );
while(!ereg('^250', $out)&&(!empty($out))){
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 5);
}
for($tries = 15; $tries > 0; $tries--){
if(ereg('^250', $out)){
if(eregi('AUTH=LOGIN|AUTH LOGIN', $out))$auth_login = TRUE;
$for_loop_hop = $out;
}elseif(empty($out)){
usleep(100000);
}
stream_set_timeout($connect, 0, 5000);
$out = fgets($connect, 1024);
stream_set_timeout($connect, 5);
}
if(!ereg('^250', $for_loop_hop))return(error('No 250 Remote: '.$for_loop_hop, $connect));
if(!isset($auth_login))return(error('No AUTH LOGIN'));
fputs ($connect, "AUTH LOGIN\r\n");
$out = fgets($connect, 1024);
if (!ereg("^334", $out))return(error('No 334 (username) Remote: '.$out, $connect));
fputs ($connect, base64_encode($username)."\r\n");
$out = fgets($connect, 1024);
if (!ereg("^334", $out))return(error('No 334 (password) Remote: '.$out, $connect));
fputs ($connect, base64_encode($password)."\r\n");
$out = fgets($connect, 1024);
if (!ereg("^235", $out))return(error('No 235 (not authenticated) Remote: '.$out, $connect));
fputs ($connect, "MAIL FROM: <{$mail_from}>\r\n");
$out = fgets($connect, 1024);
if (!ereg("^250", $out))return(error('No 250 (after MAIL FROM:) Remote: '.$out, $connect));
fputs ($connect, "RCPT TO: <{$to}>\r\n");
$out = fgets($connect, 1024);
if (!ereg("^250", $out))return(error('No 250 (after RCPT TO:) Remote: '.$out, $connect));
fputs($connect,"DATA\r\n");
$out = fgets($connect, 1024);
if (!ereg("^354", $out))return(error('No 354 (Enter mail) Remote: '.$out, $connect));
fputs($connect, "$message\r\n.\r\n");
$out = fgets($connect, 1024);
if (!ereg("^250", $out))return(error('No 250 (End of mail) Remote: '.$out, $connect));
fputs($connect,"QUIT\r\n");
fclose($connect);
return TRUE;
}
-
Sep 9, 2005, 08:51 #21
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I get: No AUTH LOGIN mail not sent
So I guess pword/username wrong. I log onto the server from my own computer(internal server) Use my own login details.
So what should I use for $username and $password?
-
Sep 9, 2005, 09:18 #22
No. Its not that!
Go to the dos command prompt and type in
telnet localhost 25
then press enter. It will return some lines starting 220. Then enter
EHLO [127.0.0.1]
then press enter. It should return some lines that start with 250. Copy those lines here so I can see them. Easiest way might be a screen grab.
-
Sep 9, 2005, 09:36 #23
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Get this...
250 - Webservertest.cte.com Hello [127.0.0.1]
250 - Turn
250 - Size 2097152
250 - DSN
250 - VRFY
250 - OK
-
Sep 9, 2005, 09:41 #24
OK! Well for my code to work it needs to return AUTH LOGIN which 99% of mailservers do. Let me think how to bypass this.
-
Sep 22, 2005, 01:28 #25
- Join Date
- Apr 2004
- Location
- dublin
- Posts
- 2,036
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Any more ideas on this? Still no solution.
Thanks.
Kevin.
Bookmarks