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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP newbie (very new) need assistance

Status
Not open for further replies.

Wulfgen

Technical User
Dec 31, 2004
283
US
I have a flash form I'm using from a downloaded tutorial - it gives basic results - and there is NO verification in Flash, (I'll get to that another time)

However - is there a way to add a autoresponder to this script? - I have a sort of one, but I am absolutely (this week) a newbie to PHP. The code that works I have below, it sends an email with the appropriate field info - believe me, it was a task for me, and many, many tests to get this to work. Dont laugh too much.
--------
Code:
<?php
//Create a temporary name for accepting the variable sent by Flash
$name =  $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$comment = $_POST['comment'];
//Some fields entered contained whitespace and we dont want them, so use function trim() to
//delete away whitespace
$name=trim($name);
$email=trim($email);
$company=trim($company);

// We use StripSlashes to delete away unwanted backslashes '\'
$comment=StripSlashes($comment);

//We are going to include the website field, and company field insid the $comment here
$message ="Contact Name : $name\n";
$message .="Contact Email : $email\n";
$message .="Contact Company : $company\n";
$message .="Comment : $comment";

//Modified this to suit your email address
$sendto='me@mydomain.com';

//Modified this for displaying the subject in your mail
$subject="Audax Contact Form";

mail($sendto,$subject,$message,"From: $name <$email>") or die("Failure");
 //clear all variables
     $name='';
     $email='';
	 $company='';
     $subject='';
	 $comment='';
     $message='';
echo ("the form has submited successfully");

?>
-----

This is the other code I have - its for another file - I tried to "add" the return part, but I screwed it up - please help.....
Code:
<?php 

$recipient = "me@mydomain.com";
$subject = "FormMail";
$date = date( "d/m/Y - H:i:s");

$msg = "***********************************\nName:   $name\n";
$msg .= "EMail: $email\n";
$msg .= "WebSite: $phone\n\n";
$msg .= "Message: $comment\n\n";
$msg .= "sent: $date";
mail($recipient, $subject, $msg, "From: <AUDAX Inc.>");
mail($email, "write here the subject of the mail","Automatic Responder\n
************************************
this is the mail sent to the sender
************************************\n
write here what u wont
", "From: <your name site>"); 
?>
 
Welcome to PHP. You are a newbie as you say - so take the right approach from the very beginning.
For example, it is important to develop troubleshooting skills and the skills to ask the right questions if one needs to ask.

My questions:
What is your question (and I don't mean "What's wrong?")?
What have you done to troubleshoot?
What are the 'symptoms' of the non working code?
 
Oh my, beating me with a stick already......

- as far as the troubleshooting skils go the first code I had to (by repeated testing) get to actually work i order to send the data back via email - and I'm proud of that - I was kinda hoping to get some help to get it to autorespond - so I did a search and after about 20 - 30 downloads/ copies of coding scripts - PHP.org, zendcode, phpbuilder, and even in the forums here, there are a lot of scripts around.

My idea was to intergrate a couple of these into something I needed, so the "whats wrong" doesnt apply here. There are no "symptoms" as I havnt gotten far enough into this as yet - if you mean symptoms like it does'nt work.... I have plenty of broken/non functioning attempted scripts [by me] and I didnt think that cluttering up this area with them would be looked upon very favorably.

It seems that by just posting my problem, has been looked at unfavorably from the get go. I'm simply asking if another feature can be added to what I've already made - with a lot of as you say "troubleshooting - presumably, non-skills"

Is'nt the idea of asking questions the way to be able to get your head around something without someone banging on them for asking? Berating me seems the way though, yep that really helps - that is if I've read your note right.
 
Nobody is beating you and there is nothing wrong with asking questions.
But if I just would answer your question if it is possible to add that, it would be "Yes". And that will not do any good either.

We are agreeing on that the idea of asking questions is to get your head around the problem. However, we'd rather help you develop the skills to solve the problem yourself than just posting an answer (Give a man a fish etc...)

"It doesn't work" is way too vague to be able to give any meaningful answer. So, let me ask you a question which you in the future will probably ask yourself:
Does it work when you remove the code you added?
 
OK here's the thing - the code at the top is the one I'm using now and it does fine. The code at the bottom is from another tutorial, however it had the auto respond feature in it, I wanted to add that to my working code.

In the second code the bit where it goes:
mail($email, "write here the subject of the mail","Automatic Responder\n
************************************
this is the mail sent to the sender
************************************\n
write here what u wont
", "From: <your name site>");
?>
is all I added, but does'nt appear to work with the original - so I tried a few others, similar, but they to broke the original code as well.

Now here I am aking if there is a way to "add it' if at all. The reason I'm using this, .... is, out of all the many scripts I've tried, this is the only one I can get to work with a Flash based form. Normally I use CGI, but from Flash........well you know....?
 
Wulfgen,

I don't know that it's your code.

I just tried a test, that included one mail right after another. It failed.
I added "sleep(2)" between the "mails" and both were sent.


Code:
mail($recipient, $subject, $msg, "From: <AUDAX Inc.>");
sleep(2);
mail($email, "write here the subject of the mail","Automatic Responder\n
************************************
this is the mail sent to the sender
************************************\n
write here what u wont
", "From: <your name site>");



Hope it's helpful.

Good Place to "Learn More">>
 
All right.
1. I would try Lrnmore's suggestion with the sleep(2).
2. Comment out the original mail line and see if you receieve the auto-response.

Suggestion:
follow the same principle as in the first mail statement, i.e. put the message into a variable:
Code:
$aRespond .= "Automatic responder\n";
$aRespond .= "*******************\n";
$aRespond .= "Whatever here .... \n";
$aRespond .= "*******************\n";
$aSubject = "Auto response";
$aFrom = 'From: <your name site>";
if (!mail($email, $aSubject,$aRespond,$aFrom)){
   echo "Mail was not sent.\n";
   echo "Email: $email\n";
   echo "Subject: $aSubject\n";
   echo "Message: $aRespond\m";
   echo "From: $aFrom\n";
}

When the mail fails, then you get all the variables displayed.
If the mail does not fail, there is probably something with the mail processing program (e.g. sendmail, whatever OS you use).
 
So it should look something like this?

Code:
<?php
//Create a temporary name for accepting the variable sent by Flash
$name =  $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$comment = $_POST['comment'];
//Some fields entered contained whitespace and we dont want them, so use function trim() to
//delete away whitespace
$name=trim($name);
$email=trim($email);
$company=trim($company);

// We use StripSlashes to delete away unwanted backslashes '\'
$comment=StripSlashes($comment);

//We are going to include the website field, and company field insid the $comment here
$message ="Contact Name : $name\n";
$message .="Contact Email : $email\n";
$message .="Contact Company : $company\n";
$message .="Comment : $comment";

//Modified this to suit your email address
$sendto='me@mydomain.com';

//Modified this for displaying the subject in your mail
$subject="Audax Contact Form";

//This is the autoresponder
$aRespond .= "Automatic responder\n";
$aRespond .= "*******************\n";
$aRespond .= "Whatever here .... \n";
$aRespond .= "*******************\n";
$aSubject = "Auto response";
$aFrom = 'From: <me@mydomain.com>";
if (!mail($email, $aSubject,$aRespond,$aFrom)){
   echo "Mail was not sent.\n";
   echo "Email: $email\n";
   echo "Subject: $aSubject\n";
   echo "Message: $aRespond\m";
   echo "From: $aFrom\n";
}
?>
 
That looks fine. Have you tried the code?

Now, a suggestion:
Never trust the user input. For example, there is no validation for the e-mail address - if it is in an acceptable format or entered at all. Some basic validation of the submitted values is a requirement for good code.
 
You're right - but I'm going to have to do that in Flash. And... I'm also looking into experimenting with checkboxes etc, But... thats another story.

Now i'm back in the office I'm going to try it out - I'll post you back, K?
 
Just a note:
Your PHP script will not be able to know with certainty who/what sent the POST to it. Therefore it is the best practice to validate within the PHP, even if client side validation is implemented. Any fairly skilled coder can write a POST mechanism that posts to your script.
 
Tried out the script but it did not work, so I tried the original again, and it did. hmmmn! This is irksome.

With the reference to the validation; Any fairly skilled coder can write a POST mechanism that posts to your script
as far as that goes, I'm no where near competent at PHP, I just started looking at it last week.

And, I would like to take a moment to thank you for your efforts in helping me with this.

Do you know Flash? I can post the flash code for you:
Code:
stop();
companyNameLoaded = new loadVars();
companyNameLoaded.load("[URL unfurl="true"]http://www.mydomain.com/audax/company.html");[/URL]
companyNameLoaded.onLoad = function(success) {
	if (success) {
		companyName.html = true;
		companyName.htmlText = this.company;
	} else {
		trace("not loaded");
	}
};
border_off_focus = 8025975;
border_on_focus = 8030344;
background_off_focus = 16777215;
background_on_focus = 15658734;
TextField.prototype.onSetFocus = function() {
	this.borderColor = border_on_focus;
	this.backgroundColor = background_on_focus;
};
TextField.prototype.onKillFocus = function() {
	this.borderColor = border_off_focus;
	this.backgroundColor = background_off_focus;
};
Selection.setFocus(nameField);
inputfield = [nameField, emailField, companyField, commentField];
myTextFormat = new TextFormat();
myTextFormat.color = 6710886;
myTextFormat.font = "Verdana, Helvetica, Tahoma";
for (var i in inputfield) {
	inputfield[i]._width = 200;
	inputfield[i].border = true;
	inputfield[i].background = true;
	inputfield[i].borderColor = 13421772;
	inputfield[i].backgroundColor = 16777215;
	inputfield[i].setNewTextFormat(myTextFormat);
}
sender = new LoadVars();
receiver = new LoadVars();
submit_btn.onRelease = function() {
	if (nameField.text === "" || (emailField.text === "" || commentField.text === "")) {
		errorField.text = "Please type in required fields";
	} else {
		indexOfAt = emailField.text.indexOf("@");
		lastIndexOfDot = emailField.text.lastIndexOf(".");
		if (indexOfAt != -1 && lastIndexOfDot != -1) {
			if (lastIndexOfDot < indexOfAt || indexOfAt == 0) {
				errorField.text = "Please verify your email.";
			} else if (lastIndexOfDot > (indexOfAt + 1)) {
				sender.name = nameField.text;
				sender.email = emailField.text;
				sender.site = siteField.text;
				sender.company = companyField.text;
				sender.comment = commentField.text;
				receiver.onLoad = function(success) {
					if (success) {
						gotoAndStop(2);
					} else {
						errorField.text = "Problem!! please resubmit";
					}
				};
				sender.sendAndLoad("sendEmail.php", receiver, "POST");
			} else {
				errorField.text = "Make sure your \'@\' and \'.\' place correctly";
			}
		} else {
			errorField.text = "Please enter correct email";
		}
	}
};
cambodiaxp.html = true;
cambodiaxpFormat = new TextFormat();
cambodiaxpFormat.url = "[URL unfurl="true"]http://www.mydomain.com/contact/";[/URL]
cambodiaxp.setTextFormat(cambodiaxpFormat);
 
1. The quote about the fairly skilled coder was not meant to reflect on you - it juste means almost anyone can post to your script by tweaking a bit of HTML.

2. Try the flash forum. I can't be of much help.

Good luck.
 
Oh I know that! -- I was enjoying a laugh at myself.

I was kinda hoping to get the form to be able to spit out a reply to whomever filled it in. Ahh well.
 
You should be able to achieve your task.
I still see nothing wrong with the code. Maybe there is some misunderstanding of how the thing works?

Code:
<?php
//Create a temporary name for accepting the variable sent by Flash
$name =  $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$comment = $_POST['comment'];
//Some fields entered contained whitespace and we dont want them, so use function trim() to
//delete away whitespace
$name=trim($name);
$email=trim($email);
$company=trim($company);

// We use StripSlashes to delete away unwanted backslashes '\'
$comment=StripSlashes($comment);

//We are going to include the website field, and company field inside the $comment here
$message ="Contact Name : $name\n";
$message .="Contact Email : $email\n";
$message .="Contact Company : $company\n";
$message .="Comment : $comment";

//Modified this to suit your email address
$sendto='me@mydomain.com';

//Modified this for displaying the subject in your mail
$subject="Audax Contact Form";

##### mail to $sendto ######
if (!mail($sendto, $subject,$message,'From: <me@mydomain.com>")){
   echo "First mail was not sent.\n";
   echo "Email: $sendto\n";
   echo "Subject: $subject\n";
   echo "Message: $message\n";
}

##### This is the autoresponder ####
$aRespond .= "Automatic responder\n";
$aRespond .= "*******************\n";
$aRespond .= "Whatever here .... \n";
$aRespond .= "*******************\n";
$aSubject = "Auto response";
$aFrom = 'From: <me@mydomain.com>";
if (!mail($email, $aSubject,$aRespond,$aFrom)){
   echo "Mail was not sent.\n";
   echo "Email: $email\n";
   echo "Subject: $aSubject\n";
   echo "Message: $aRespond\n";
   echo "From: $aFrom\n";
}
?>

What happens if you run the above?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top