Current location: Hot Scripts Forums » Programming Languages » PHP » SMTP connect instead of using mail()


SMTP connect instead of using mail()

Reply
  #1 (permalink)  
Old 06-24-03, 05:46 PM
spinicrus spinicrus is offline
Newbie Coder
 
Join Date: Jun 2003
Location: else where
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation SMTP connect instead of using mail()

hi there !

please read this first and after maybe you can "light me" :



<?php
$smtp_server = "smtpserver.com";
$port = 25;
$mydomain = "mydomain.com";
$username = "username"; $password = "password";
$sender = "sender email";
$recipient = "email that the content will be sent to";
$subject = "the subject";
$content = "the message";

// SMTP connection

$handle = fsockopen($smtp_server,$port);
fputs($handle, "EHLO $mydomain\r\n");

// SMTP authorization
fputs($handle, "AUTH LOGIN\r\n");
fputs($handle, base64_encode($username)."\r\n");
fputs($handle, base64_encode($password)."\r\n");

// Send out the e-mail
fputs($handle, "MAIL FROM:<$sender>\r\n");
fputs($handle, "RCPT TO:<$recipient>\r\n");
fputs($handle, "DATA\r\n");
fputs($handle, "To: $recipient\n");
fputs($handle, "Subject: $subject\n\n");
fputs($handle, "$content\r\n");
fputs($handle, ".\r\n");

// Close connection to SMTP server
fputs($handle, "QUIT\r\n");
?>




ok

now i want to ask you how do i pass information from a html form to the php script, i mean to the "sender" , "subject" , "content" ?

i know there is a "post", using $get method, but i don't know how to do it.


pls help me !
Reply With Quote
  #2 (permalink)  
Old 06-24-03, 06:06 PM
jv2222 jv2222 is offline
The Freshmaker
 
Join Date: Jun 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Let me get this straight... you post a script that talks directly to an SMTP server....

and you're asking how to get variables from a form

Wow. That's wierd.
__________________
Author of <a href=http://www.hotscripts.com/Detailed/18290.html target=_blank>ezSQL</a> (makes life soooo easy when working with databases)
Reply With Quote
  #3 (permalink)  
Old 06-25-03, 01:51 AM
Chris Boulton Chris Boulton is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Sydney, Australia
Posts: 208
Thanks: 0
Thanked 0 Times in 0 Posts
jv2222, plese only make useful posts...

Here is a simple form page..

Code:
<html>
<head>
</head>
<body>
<form method="POST" action="[script name]">
Recipient: <input type="text" name="recipient"><br>
Subject: <input type="text" name="subject"><br>
Content: <textarea name="content"></textarea>
<input type="submit">
</form>
</body>
</html>
__________________
Chris Boulton
SurfiOnline!
MyBulletinBoard
Reply With Quote
  #4 (permalink)  
Old 06-25-03, 05:29 PM
spinicrus spinicrus is offline
Newbie Coder
 
Join Date: Jun 2003
Location: else where
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
hey, i resolved that problem above...
but i'm into a big shit:

the smtp mail works fine, but there is a problem, and i think it's about the lenght of the messege being send, the size of it...
i tried to send a message both with $_GET and $_POST methods, but using the $_GET the browser(IE) didn't take the command, when the message was to long, and with $_POST, the message looked like sent, but there was nothing coming in my inbox...
do you have any ideea ?
what do you thing i should do ?
Reply With Quote
  #5 (permalink)  
Old 06-25-03, 05:36 PM
spinicrus spinicrus is offline
Newbie Coder
 
Join Date: Jun 2003
Location: else where
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
hey, jv2222, thanks for your help !
if you would be the single really good programmer on this earth, then you'd be the only one...

Last edited by spinicrus; 06-25-03 at 05:41 PM.
Reply With Quote
  #6 (permalink)  
Old 06-26-03, 02:32 AM
jv2222 jv2222 is offline
The Freshmaker
 
Join Date: Jun 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
After the for (in your php script) put this. It might help. It's a print out of all the variables as they were recieved by php.

print_r($_POST);
__________________
Author of <a href=http://www.hotscripts.com/Detailed/18290.html target=_blank>ezSQL</a> (makes life soooo easy when working with databases)
Reply With Quote
  #7 (permalink)  
Old 06-26-03, 09:56 AM
spinicrus spinicrus is offline
Newbie Coder
 
Join Date: Jun 2003
Location: else where
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy

click this first:

http://www.metalborn.ro/capture.gif


this is the original text:

it is not becouse of the lenght of the message... it's about the breakets... there are interpreted wrong by the php... i read something like this.... so watch this :

"After the for (in your php script) put this. It might help. It's a print out of all the variables as they were recieved by php."

Last edited by spinicrus; 06-26-03 at 10:07 AM.
Reply With Quote
  #8 (permalink)  
Old 06-27-03, 06:30 PM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
I'd change this script to the following...
PHP Code:

<?php 

  $smtp_server 
"smtpserver.com"
  
$port 25
  
$mydomain "mydomain.com"
  
$username "username";
  
$password "password"
  
$sender "sender email"

  if (ISSet(
$_REQUEST["recipient"]))
  {
    
$recipient $_REQUEST["recipient"]; 
  }
  else
  {
    Die(
"Recipient is a required field...");
  }
  
  if (ISSet(
$_REQUEST["subject"]))
  {
    
$subject $_REQUEST["subject"]; 
  }
  else
  {
    
$subject ""
  }
  
  if (ISSet(
$_REQUEST["content"]))
  {
    
$content $_REQUEST["content"]; 
  }
  else
  {
    Die(
"Content is a required field...");
  }
  
  
// SMTP connection 

  
$handle fsockopen($smtp_server$port); 
  
fputs($handle"EHLO " $mydomain "\r\n"); 

  
// SMTP authorization 
  
fputs($handle"AUTH LOGIN\r\n"); 
  
fputs($handlebase64_encode($username)."\r\n"); 
  
fputs($handlebase64_encode($password)."\r\n"); 

  
// Send out the e-mail 
  
fputs($handle"MAIL FROM:<" $sender ">\r\n"); 
  
fputs($handle"RCPT TO:<" $recipient ">\r\n"); 
  
fputs($handle"DATA\r\n"); 
  
fputs($handle"To: " $recipient "\n"); 
  
fputs($handle"Subject: " $subject "\n\n"); 
  
fputs($handle$content "\r\n"); 
  
fputs($handle".\r\n"); 

  
// Close connection to SMTP server 
  
fputs($handle"QUIT\r\n"); 
?>
The form as per Chris
PHP Code:

<HTML>

  <
HEAD>
  </
HEAD>
  <
BODY>
    <
FORM METHOD="POST" ACTION="[script name]">
      
Recipient: <INPUT TYPE="TEXT" NAME="recipient"><BR>
      
Subject: <INPUT TYPE="TEXT" NAME="subject"><BR>
      
Content: <TEXTAREA NAME="content"></TEXTAREA>
      <
INPUT TYPE="SUBMIT">
    </
FORM>
  </
BODY>
</
HTML
I don't know if this will help at all...
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
  #9 (permalink)  
Old 06-27-03, 08:33 PM
spinicrus spinicrus is offline
Newbie Coder
 
Join Date: Jun 2003
Location: else where
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb

hey, that's a good ideea, i understand what you want with that... it might work...
tnx a lot !
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with SMTP Gateway hunsaken PHP 1 09-09-03 12:19 PM
adding more variables to the mail() result spinicrus PHP 6 08-28-03 04:55 PM
Send email by ASP mail nghiapk ASP 1 07-09-03 12:47 AM
send mail to user onlynils New Members & Introductions 1 07-04-03 01:18 PM
No mail when reply is posted to a thread. phpkid HotScripts Site Bug Reports 5 06-24-03 11:45 AM


All times are GMT -5. The time now is 08:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.