Jump to content


Photo

Send Mail using PHP


  • Please log in to reply
5 replies to this topic

#1 drcdeath

drcdeath
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 28 October 2006 - 10:56 AM

Hey, I'm a noob in PHP. I only started like a couple of months ago. I have done a file upload but that's it so far.

Now I want to create a contact page using php for my website. I have build a form with all the necessary fields and the button and this is my code:

<font color="white">
<?php
$name = 'txtname.text';
$email = 'txtemail.text';
$message = 'txtmessage.text';
$to = $email;
$subject = "Contact Via J-Rose Computerisation Website";
$body = $message;
ini_set("SMTP","smtp.googlemail.com");
if (mail($email, $subject, $message)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>
</font>
The font tags are in there because my page colour is dark I need a light color for it to show correctly. Now that, doesn't work. I have an account on somebody's else's server because my own webspace doesn't support php. There is no php.ini file so I tried creating one, that didn't work. This is the error message I got:

Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first m1sm502887ugc in E:\webspace\standard\death_v8\send_mail.php on line 10

Message delivery failed...


Hopefully you php-literate people can tell me what's wrong.

Thanks.

#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 28 October 2006 - 11:55 AM

STARTTLS is a method of sending encrypted email over a standard SMTP port. I am not exactly sure how you would go about getting this right with PHP, and have seen a lot of people being referred to the Pear::Mail package which provides support for STARTTLS in PHP5.1 and higher.

RFC3207 SMTP Service Extension for Secure SMTP over Transport Layer Security



#3 drcdeath

drcdeath
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 28 October 2006 - 12:21 PM

I edited the code to another smtp server, and it worked! But one thing,

<font color="white" size="6"><b><p align="center">
<?php
$name = txtname.text;
$email = 'ozzy.rose';
$message = txtmessage;
$to = $email;
$subject = "Contact Via J-Rose Computerisation Website";
$body = $message;
ini_set("SMTP","smtp.virgin.net");
if (mail($email, $subject, $message)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>
</font></b></p>

That's my code. I also have a text area which I want to be my message. At the moment when I send mail the message is: "txtmessage" - check the code. txtmessage is the name of the text area on my form. If you could modify the code so it worked, that would be great.

Thanks.

#4 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 28 October 2006 - 12:57 PM

When your user fills out the form and then clicks submit, all the values of the fields on the form are POSTed to the script specified in the action of the form, if the form's method is set to POST. Therefore, in your script you would need to retrieve these values in order to use them in your script. You need to be very careful when using data that a user submits - you need to validate the values against criteria that you specify. For instance, if you ask the user to submit their email address, then you would need to make sure that the user submits a valid email address.

So then, I will show you how to retrieve your txtmessage field values, and then you can do the rest.

mailscript.php
<?php

$message = $_POST['txtmessage']; //Retrieve the value for the form field named "txtmessage"

//You would then need to write some code that validates this data to make sure that illegal characters are not being submitted, etc.

?>


#5 drcdeath

drcdeath
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 28 October 2006 - 01:14 PM

I did it, it sent the e-mail, but with no body. I entered a message in the box and nothing happened. It sent and nothing was in the e-mail.

#6 drcdeath

drcdeath
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 28 October 2006 - 01:21 PM

Scratch that last, fixed :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users