Anyone who knows PHP

I need a very simple script that sends a one-line message (that contains two static hyperlinks) when a button is pressed in a php file to an email address. I’m in a huge hurry so I don’t have time to go research, but I know it’s very easy to do, since I set up a form email thing on my website with a script I found. But I can’t use this script since I don’t want to mail the contents of all form items on a page; just a static notification message that never changes.

Thx,
Jordan

It depends on who you want it sent to.

But I think the mail command goes something like:



mail($_POST['email'], 'Subject Line goes here', $body, 'From:[email protected]');



Use the “$_POST[‘email’]” if the form your submitting has there email address on it, and is assigning it to the variable $email.

Replace “Subject line goes here” with whatever the subject line should be.

“$body” is whatever you want the body of your email to say. For instance in your case it might be:




$body= "[link1](whatever) [link2](whatever2) 
or please copy and paste these links into your browser: link1 link2.;


It doesn’t matter where you define $body in your script, though its probably best to put it before the mail function.

From is your email address I believe.

Be sure to have the <?php tags at the beginning and ?> at the end.

Also make sure that the form in the HTML has this set as the action attribute set to use this php script.

Good luck and if there is anything I can clarify please ask.

I was trying to put the hyperlinks in there with the <a href> tags, but it changes the < > symbols to “<” in the code, so that that is just what it shows in the browser. I can’t seem to make it send HTML (or rich text format) emails. But I did discover that you have to have (") instead of (") around code you are sending, so it doesn’t try to read it. Perhaps you can do something similar with < > tags? I was looking at other PHP stuff and I was wondering if using the echo command would work in $body?

I’m not entirely sure, but I think $body is actually a variable that you assign a string to, not something you can put an echo in, but its worth a shot. You could try instead of putting double quotes around the body contents try putting single quotes:


$body='content here';

I’m not sure if that works though, I don’t have my reference with me right now so I forget if its double or single quotes that print whatever you put within them. I’m not sure about the tag problem, but php should be able to parse the html and php. Try the quotes and I’ll try to find a solution, because I know there is a way.

Do you know how I could store a value from an HTML text input in the $subject (or for that matter, any other) field?

By text input do you mean:



&lt;form action="myscript.php" method="post"&gt;


subject&lt;/p&gt;&lt;input type="text" name="subject" size="20 maxlength= "20"&gt;


I believe that should assign whatever is in the text field to the variable for the script to process as long as when you first bring the variable into php you use this:

($_POST['subject'])

That should assign the input string (value entered into subject) to the variable $subject. Then you should be able to put it something like this:



mail($_POST['email'], $_POST['subject'], $body,'From:[email protected]');


I suppose it would also be possible using this method to assign multiple values to $subject and make it an array that could send personalized information if required, though, I am horrible at arrays, so I will be able to help you minimally there.

Also relating to earlier, to print out the value of a variable in an echo statement you have to use something like:



echo "var is equal to $var"

With double quotes instead of single ones.

Does any of this help?

Yeah… almost. I got this error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/kjames/www/zevran/emailme.php on line 23

this is my line 23:

mail($mailto, $subject, $content, “From: $_POST[‘Email’]”);

I have the $mailto, $subject, $content variables stored somewhere else in the file. It was working before, but I am trying to improve it with the From address.

To get your <a href and things working you have to make the mail type into html/text… if you don’t do that it will make it into plain text and change it indeed.

Like here:

	$mailheaders = "From: $myplace
";
	$mailheaders .= "Reply-To: $addy
";
	$mailheaders .= "Content-type: text/html";

	mail($recipient, $subject, $msg, $mailheaders);

And in this $recipient is the email adres to sent to… $ subject is the subject… and $msg is the message to be sent.

OK, now I’ve got formatting questions (I refuse to show you the results until I get it all to look right :wink: ). First, how do you make the php script generate bold style HTML text? The same thing kind of applies to my second question, which I went into before: how do you make php generate HTML hyperlinks, or display remote images in the email it sends?

To make bold you could probably just put the and (those are bold right?) tags around what you want to be bold like:


echo "<b>$variable</b>"

That should make it print the variable in bold. PHP should be able to parse the HTML tags within the quotes since double quotes will give you values instead of literal writing.

It should be similar for generating links like:


echo "[$variable](http://...)"

OR

echo "&lt;a&gt; $variable &lt;/a&gt;"

echo "![...whatever](...whatever)&lt;/img&gt;


You get the idea right? You just have to print whatever you want to be in the HTML right into an echo statement.

Thanks, guys.
Here are the results:
http://zevran.kjames.org/emailme.htm

I made the html file submit the values to send.php, so it is a seperate file.