Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with webpage submit form 1

Status
Not open for further replies.

Enkrypted

Technical User
Sep 18, 2002
663
US
I had made a post over on the Linux board, and was referred to post here for more help. Here is the post I made over there:

Hey guys, I was wondering if any of you might be able to help me out. I am in a bit of a jam. We recently moved our webhosting provider from a Windows based system to a Linux based system. Everything works fine except I forgot about the contact submit form. That will not work because it is an ASP page. I need to find a way to convert it so it will work without having to redo the entire page.

Basically when you get to our contact page (which is html) and enter your info. You click on the submit button and it is supposed to e-mail us the info from the page and redirect to a thank you page.

The code for the ASP page (the background submit process) is in VBScript and is as follows:

<%@ Language=VBScript %>
<%


Dim MyBody
Dim MyBodyEnc
Dim MyBodyFinal
Dim MyCDONTSMail


MyBody = "On " & now & " someone sent an email from the Contact page. "
MyBody = MyBody & " The following information was sent." & Chr(13) & Chr(13)
For Each x In Request.Form
If Request.form(x) <> "submit" then
MyBody = MyBody & x & ": " & Request.Form(x) & Chr(13)
End If
next
response.Write(MyBody)
Dim sSubjectString
sSubjectString = "Contact Inquiry form"

SendEmail = 1
If SendEmail = 1 THEN
Set MyCDONTSMail = CreateObject("CDONTS.NewMail")
MyCDONTSMail.From= "no-reply@sharperimpressionspainting.com"
MyCDONTSMail.To= "sipainting@sharperimpressionspainting.com"
MyCDONTSMail.Bcc= "forefrontweb@gmail.com"
MyCDONTSMail.Subject= sSubjectString

MyCDONTSMail.Body = MyBody
MyCDONTSMail.Send
set MyCDONTSMail=nothing
End If

response.redirect("/thankyou.html")
%>

I was wondering if any of you guys might be able to help me convert it or find a solution to get this to work. I'm not real familiar with this at all and am in need of help in a big way. I appreciate any help. Thanks




Since that time, I have managed to get the ASP page re-written in PHP, but have stumbled onto another problem. It does not e-mail the information. It will process and go to the follow up screen (the Thank You screen) but the e-mail never arrives at the destination. Here is the code I have for the re-written ASP page:

<?
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "sipainting@sharperimpressionspainting.com", "Contact Inquiry Form",
$message, "From: $email" );
header( "Location: );
?>


Could any of you help me figure where I went wrong? TIA!

Enkrypted
A+
 
Shouldn't it be something like this? :

Code:
$email = $_POST['email'] ;
$message = $_POST['message'] ;

if(
    mail(
    "sipainting@sharperimpressionspainting.com", 
    "Contact Inquiry Form",
    $message,
    "From: $email"
    )
) {

header( "Location: [URL unfurl="true"]http://www.sharperimpressionspainting.com/thankyou.html"[/URL] );
exit;

} else {

echo"email not sent";

}
 
I just tried that and it did not seem to work. Just to make certain of things...on the Contact page (the page that contains the Submit button) here is the code for the Submit form:

<form id="FormName" action="submitemail.php" method="post" name="FormName">

Then it has all the tables/design for the form in here

<input type="submit" name="submit" value="Submit" tabindex="10" />

Enkrypted
A+
 
The mail() needs to access the sendmail binary to do any mailing. So, if your httpd user is not authorized to use sendmail or if sendmail is not in your path, mailing will fail. For most mailing need from PHP, I like to use PHPMailer.

Code:
require('class.phpmailer.php');
require('class.smtp.php');

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = [your mail server IP];
$mail->From = "sipainting@sharperimpressionspainting.com";
$mail->FromName = "sipainting";
$mail->AddAddress($_POST['email']);
$mail->Subject = "Contact Inquiry form";
$mail->Body = $_POST['message'];
$mail->WordWrap = 72;
if($mail->Send())
{
  header("location:thankyou.html" );
}

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Ok, I have the files uploaded, but forgive my ignorance. I'm new to all this PHP and website stuff. The readme says to

Copy class.phpmailer.php into your php.ini include_path

And when I look at the info in the php.ini file it looks like this

Windows: "\path1;\path2"
include_path = ".:/usr/lib/php:/usr/local/lib/php"


So what would the path for it look like. On my webserver, I have the normal files/folders you would find and all the website files in the public html/
root.jpg


root2.jpg


Enkrypted
A+
 
If submitemail.php is in the same folder as both class.phpmailer.php & class.smtp.php then my example above holds.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Ok, all 2 files are in the same directory, and I have not added/changed anything to the php include path. I entered the following into my submitmail.php file and noticed the shaded and dark text (I'm assuming I did something wrong)

php.jpg


After trying to submit the info I get the following message:

Parse error: syntax error, unexpected '[' in /home/sharperi/public_html/submitemail.php on line 7

(I intentionally replaced the Ip with x's)


I appreciate all the help you guys are giving me on this

Enkrypted
A+
 
Sorry if I didn't mention it earlier, but [your mail server IP] was a placeholder and was to be replaced with an IP address WITHOUT the square brackets.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Ok, I made sure that the brackets were removed and tried it again. This time it is giving me the follow error:

Parse error: syntax error, unexpected T_DNUMBER in /home/sharperi/public_html/submitemail.php on line 7

Enkrypted
A+
 
No I did not have them in quotations. I put the quotations around them and got this error:

Warning: fsockopen() [function.fsockopen]: unable to connect to xxx.xxx.xxx:25 in /home/sharperi/public_html/class.smtp.php on line 105

I have tried it with and without the port number after the IP address

Enkrypted
A+
 
that means that the server at the IP address you specify is not allowing incoming SMTP connections on port 25.
 
Ok, it appears that the e-mails are coming through, but are delayed. I am trying to find out the time of the delay. So it appears to work, but something is still not correct. I need to try to find out why it can't communicate with port 25 properly

Enkrypted
A+
 
I found the following while I was searching for a resolution. I tried it out and it didn't give any errors and went right to the thank you page. Let me know if you guys think this code works out alright:


<?
function authMail($from, $namefrom, $to, $nameto, $subject, $message)
{

/* your configuration here */

$smtpServer = "mail.yourdomain.com"; //ip accepted as well
$port = "25"; // should be 25 by default
$timeout = "30"; //typical timeout. try 45 for slow servers
$username = "webform"; //the login for your smtp
$password = "passhere"; //the pass for your smtp
$localhost = "127.0.0.1"; //this seems to work always
$newLine = "\r\n"; //var just for nelines in MS
$secure = 0; //change to 1 if you need a secure connect

/* you shouldn't need to mod anything else */

//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected to: $smtpResponse";
}

//say HELO to our little friend
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse'] = "$smtpResponse";

//start a tls session if needed
if($secure)
{
fputs($smtpConnect, "STARTTLS". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['tlsresponse'] = "$smtpResponse";

//you have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";
}

//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";

//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";

//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";

//email from
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";

//email to
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";

//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$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($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
return($logArray);
}
?>

Enkrypted
A+
 
In essence, what you have listed is the same as what PHPMailer is trying to do. Are you getting mail with this new script?

I would like to cover some bases so that we don't waste time doing things we really shouldn't be doing.
1. All Linux servers have a local MTA (Mail Transfer Agent/Mail Server) that may or may not be running. Thus sending mail to 127.0.0.1 (localhost) may or may not work.

2. Even if you succeed on queuing a mail on 127.0.0.1, the local MTA may not be configured to send mail externally. Queued mail will be bounced but you wouldn't know about it.

3. Lots of MTAs filter suspicious (SPAM) email. By not sending mail through the proper servers, you mail will be flagged suspect for mismatched DNS, wrong sender domain, etc and will be held or deleted.

4. Your hosting company would have given you a mail server IP. Use that and nothing else.


--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
No. That last script that I listed did not send any mail. My ISP has assigned our e-mail to mail.sharperimpressionspainting.com in which I have given them MX records which should point back to our exchange server. So does that mean I would have to put that as the local host?

Also, I have been trying random scripts that I come across while doing research. The following script below does actually send an e-mail to a yahoo account I had setup (for some reason it is not coming to my exchange server...it is being sent from the account setup with my hosting provider):

<?php

// Name
$header="from: $name <$mail_from>";

// Mail of sender
$mail_from="$custmail";

// Phone Number
$phone="$phone";

// Comments
$comments="$comments";


// Enter your email address
$to ='sipainting@yahoo.com';

$send_contact=mail($to,$header,$mail,$phone,$comments);

// Check, if message sent to your email
{
header( 'Location: /thankyou.html' ) ;
}
?>

It appears this script is sending from the mail.sharperimpressionspainting.com that the webhost originally assigned.

I know I seem to be jumping around alot and it would be better to stick with one thing and keep working at it until it is resolved. I just need to get the e-mails from the website one way or another as my boss is riding me about this. Even if I can get something temporary setup until I can get a better script going.

Zeland, Is there anyway I can e-mail you? Maybe I can send you the pages so you can get a better look into them.

Enkrypted
A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top