Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need help.........Please help me out on this.
Old 12-06-2010, 04:45 AM Need help.........Please help me out on this.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Hi Forum,

I am trying to send email using SMTP authentication.

Please find the code I am using.....

There is no error, its showing message sent.

But I didn't receive any email.

PHP Code:
function authgMail($from$namefrom$to$nameto$subject$message) {
    
$smtpServer "smtp.domain.com";   //ip address of the mail server.  This can also be the local domain name
    
$port "25";                    // should be 25 by default, but needs to be whichever port the mail server will be using for smtp
    
$timeout "45";                 // typical timeout. try 45 for slow servers
    
$username "info@domain.com"// the login for your smtp
    
$password "******";           // the password for your smtp
    
$localhost "http://webmail.ambarvyparkendra.com";      // Defined for the web server.  Since this is where we are gathering the details for the email
    
$newLine "\r\n";           // aka, carrage return line feed. var just for newlines in MS
    
$secure 0;                  // change to 1 if your server is running under SSL
    //connect to the host and port
    
$smtpConnect fsockopen($smtpServer$port$errno$errstr$timeout);
    
$smtpResponse fgets($smtpConnect4096);
    if(empty(
$smtpConnect)) {
       
$output "Failed to connect: $smtpResponse";
       echo 
$output;
       return 
$output;
    }
    else {
       
$logArray['connection'] = "<p>Connected to: $smtpResponse";
       echo 
"<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
    }
    
    
//you have to say HELO again after TLS is started
       
fputs($smtpConnect"HELO $localhost"$newLine);
       
$smtpResponse fgets($smtpConnect4096);
       
$logArray['heloresponse2'] = "$smtpResponse";
    
//request for auth login
    
fputs($smtpConnect,"AUTH LOGIN" $newLine);
    
$smtpResponse fgets($smtpConnect4096);
    
$logArray['authrequest'] = "$smtpResponse";
    
    
//send the username
    
fputs($smtpConnectbase64_encode($username) . $newLine);
    
$smtpResponse fgets($smtpConnect4096);
    
$logArray['authusername'] = "$smtpResponse";
    
    
//send the password
    
fputs($smtpConnectbase64_encode($password) . $newLine);
    
$smtpResponse fgets($smtpConnect4096);
    
$logArray['authpassword'] = "$smtpResponse";
    
    
//email from
    
fputs($smtpConnect"MAIL FROM: <$from>" $newLine);
    
$smtpResponse fgets($smtpConnect4096);
    
$logArray['mailfromresponse'] = "$smtpResponse";
    
    
//email to
    
fputs($smtpConnect"RCPT TO: <$to>" $newLine);
    
$smtpResponse fgets($smtpConnect4096);
    
$logArray['mailtoresponse'] = "$smtpResponse";
    
    
//the email
    
fputs($smtpConnect"DATA" $newLine);
    
$smtpResponse fgets($smtpConnect4096);
    
$logArray['data1response'] = "$smtpResponse";
    
    
//construct headers
    
$headers "MIME-Version: 1.0" $newLine;
    
$headers .= "Content-type: text/html; charset=iso-8859-1" $newLine;
    
$headers .= "To: $nameto <$to>" $newLine;
    
$headers .= "From: $namefrom <$from>" $newLine;
    
    
//observe the . after the newline, it signals the end of message
    
fputs($smtpConnect"To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
    
$smtpResponse fgets($smtpConnect4096);
    
$logArray['data2response'] = "$smtpResponse";
    
    
// say goodbye
    
fputs($smtpConnect,"QUIT" $newLine);
    
$smtpResponse fgets($smtpConnect4096);
    
$logArray['quitresponse'] = "$smtpResponse";
    
$logArray['quitcode'] = substr($smtpResponse,0,3);
    
fclose($smtpConnect);
    
//a return value of 221 in $retVal["quitcode"] is a success
    
return($logArray);
    }
    
$err=0;  // so far, so good
$err_msg="";

if(
$_POST['name']!="") { echo $_POST['name']."<br>"; }
else {
  
$err=1;
  
$err_msg="You must include your name";
}

if(
$_POST['phone']!="") {echo $_POST['phone']."<br>"; }
else {
  
$err=1;
  
$err_msg="You must include a daytime phone number.";
}
if(
$_POST['streetaddress']!="") { echo $_POST['streetaddress']."<br>"; }
else {
  
$err=1;
  
$err_msg="You must include your address.";
}
if(
$_POST['city']!="") { echo $_POST['city']."<br>"; }
else {
  
$err=1;
  
$err_msg="You must include the city.";
}
// Check for the existence of an AT symbol inside the email.
if (strpos($_POST['email'],"@")) { echo $_POST['email']."<br>"; } 
else {
  
$err=1;
  
$err_msg="You must include a current email address.";
}
if(
$_POST['email']!="") { echo $_POST['email']."<br>"; }
else {
  
$err=1;
  
$err_msg="You must include your e-mail address.";
}

echo 
$err_msg;

if(
$err<=0) {
  
$from="info@domain.com";
  
$namefrom="Customer Care Department of domain.com";
  
$to "myemail@yahoo.com";
  
$nameto "Admin";
  
$subject "An email to Admin";
  
$message "Hi Admin, this is a testing email.";
  
// this is it, lets send that email!
  
if(authgMail($from$namefrom$to$nameto$subject$message))
  {
    echo 
"Message Sent!";  
   }
   else
   {
      echo 
"Error Message cannot send!"
   }
}
else {
  echo 
"<p /> This form was not filled out correctly, please correct any mistakes.";

Please Please Please help.

Thanks in advance!!!
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-06-2010, 07:15 AM Re: Need help.........Please help me out on this.
Skilled Talker

Posts: 76
Name: Nick Cousins
Location: Northern Ireland
Trades: 0
My advice would be to use PuTTY or a similar Telnet client to connect to the SMTP server and carry out a session manually to verify that the commands that your script are passing to the server are being interpreted correctly.

If all goes according to plan, and you still don't receive the mail then it's likely down to some kind of spam filtering, look into SPF records, try and disable spam filtering on the receiving end if possible.

Let us know if you get it fixed, or if you have further info from testing this way.
__________________
Join
Please login or register to view this content. Registration is FREE


Knowledge is power. Never underestimate the power of stupid people in large numbers.

HandCoder is offline
Reply With Quote
View Public Profile Visit HandCoder's homepage!
 
Old 12-06-2010, 07:42 AM Re: Need help.........Please help me out on this.
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Ask sys admin or hosting company what the SMTP logs show for the emails you're trying -- give them date/time you tried it and the to address.
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-07-2010, 12:31 AM Re: Need help.........Please help me out on this.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Its working fine till here, means connection made successfully.

and contuining.....

PHP Code:
 else {
       
$logArray['connection'] = "<p>Connected to: $smtpResponse";
       echo 
"<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
    } 
But no further response, I don't know what to do as there are no mistakes shown in the code.

Please let me know if there any other way to authenticate email.

Thanks
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 12-09-2010, 03:18 AM Re: Need help.........Please help me out on this.
Novice Talker

Posts: 5
Name: selin asel
Trades: 0
as i check your code, there's no error. you can contact your host administrator and ask for the answer.
selinasel is offline
Reply With Quote
View Public Profile Visit selinasel's homepage!
 
Old 12-10-2010, 06:48 AM Re: Need help.........Please help me out on this.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
You are right, this was a server problem, I tried it with another server and its working fine now.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need help.........Please help me out on this.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.48476 seconds with 12 queries