Jump to content

Send Mail using PHP


drcdeath

Recommended Posts

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:

[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>
[/code]
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:

[quote="Error Message]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...[/quote]

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

Thanks.
Link to comment
Share on other sites

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 [url=http://pear.php.net/package/Mail]Pear::Mail[/url] package which provides support for STARTTLS in PHP5.1 and higher.

[url=http://www.rfc-archive.org/getrfc.php?rfc=3207]RFC3207 SMTP Service Extension for Secure SMTP over Transport Layer Security[/url]

Link to comment
Share on other sites

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

[code]
<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>
[/code]

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.
Link to comment
Share on other sites

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
[code]
<?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.

?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.