Jump to content

Email form


Darnel

Recommended Posts

Hi, Im sort of new to PHP.

 

I currently have this code

if(!empty($myrow['email'])){
echo "<a href=\"mailto: ".$myrow['email']."\">".$myrow['email'];
echo "</a><br>";}

Which just displays a email from the database and when clicked opens Outlook or some other email program.

 

What i'm trying to do is hide the email and in its place put a link like "Contact" or a simple form that would send a email from my website to that email address.

 

Does any one know any links to tutorials or at least a name for a script that would allow me to do this?

 

Cheers!

Link to comment
Share on other sites

you need to create a form that collects the minimum following feilds

username

useremail

usermessage

 

then you process the form with php and generate the email to be sent

 

look here for basics on sending email with php

 

http://php.net/manual/en/function.mail.php

 

when you have this working the way you want be sure to implement some sort of security on your form, something like captcha, so that rogue bots cannot spam you with multitudes of unwanted messages

 

http://www.phpcaptcha.org/

Link to comment
Share on other sites

Depends who your client is. where does this ($myrow['email'])  come from? Is it out of a database table or a user has entered it. You can't hide the email address in a mail to. You can have a contact us that takes tou to a form to fill in. This would not reveil the sending email address.

Link to comment
Share on other sites

you need to create a form that collects the minimum following feilds

username

useremail

usermessage

 

then you process the form with php and generate the email to be sent

 

look here for basics on sending email with php

 

http://php.net/manual/en/function.mail.php

 

when you have this working the way you want be sure to implement some sort of security on your form, something like captcha, so that rogue bots cannot spam you with multitudes of unwanted messages

 

http://www.phpcaptcha.org/

 

Thanks I will have a look here.

 

Depends who your client is. where does this ($myrow['email'])  come from? Is it out of a database table or a user has entered it. You can't hide the email address in a mail to. You can have a contact us that takes tou to a form to fill in. This would not reveil the sending email address.

 

It is coming from a Mysql database that a user has entered

Link to comment
Share on other sites

Hey Darnel,

 

Correct me if I'm wrong but am I correct in saying all you are wishing to do is display a link that says 'Contact' that when clicked open up the users email client with a new email message to the email address supplied from the DB?

 

If so, all you need to do is replace your code with the folowing (not tested):

 

if(!empty($myrow['email'])){
        echo "<a href=\"mailto: $myrow['email']\">Contact</a>";         
}

 

That should just display the word 'Contact' as a hyperlink that when clicked opens up the users email client.

 

As the previous posters have stated, the other option would be to create a form that the user fills out and submits, then create a php script that forwards the data to an a specified email address.  Straight forward enough to do, let me know if you need any help with that.

 

Link to comment
Share on other sites

Yes, I now have a form that send a message when i specify

$to = "withsome@email.com";

 

Form

<form id="formail" action="" method ="post">
<label>Name : </label>
<input type="text" name="name" id="name" />
<label>Your mail :</label>
<input type="text" name="mail" id="mail" />
<label>Subject : </label>
<input type="text" name="subject" id="subject" />
<label>Text :</label>
<textarea name="text" id="text" cols="40″ rows="10″></textarea>
<input type="submit" value="send mail" id="sendmail" name="sendmail" />
</form>

 

Php code

<?php
$mail = $_POST['mail'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$text = $_POST['text'];
$to = "withsome@email.com";
$message =" You received  a mail from ".$mail;
$message .=" Text of the message : ".$text;
if(mail($to, $subject,$message)){
echo "mail successfully sent";
}
else{
echo "Error mail not sent";
}

?>

 

Now all i'm trying to do is to set

$to = "withsome@email.com";

to something like

$to = $myrow['email'];

So that the recipient would be a specified email address from the database.

 

I know i'm making this harder than it is  ::)

 

Cheers!

 

Link to comment
Share on other sites

Cool, so all you need to do then is add you SQL query before setting your variables in the PHP file.

 

So something like:

 

<?php
$sql = mysql_query("SELECT * FROM tablename");
$myrow = mysql_fetch_assoc($sql);

$mail = $_POST['mail'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$text = $_POST['text'];
$to = $myrow['email'];
$message =" You received  a mail from ".$mail;
$message .=" Text of the message : ".$text;
if(mail($to, $subject,$message)){
echo "mail successfully sent";
}
else{
echo "Error mail not sent";
}
?>

 

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.