Darnel Posted May 21, 2011 Share Posted May 21, 2011 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! Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted May 21, 2011 Share Posted May 21, 2011 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/ Quote Link to comment Share on other sites More sharing options...
otuatail Posted May 21, 2011 Share Posted May 21, 2011 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. Quote Link to comment Share on other sites More sharing options...
Darnel Posted May 21, 2011 Author Share Posted May 21, 2011 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 Quote Link to comment Share on other sites More sharing options...
mkmDesign Posted May 21, 2011 Share Posted May 21, 2011 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. Quote Link to comment Share on other sites More sharing options...
Darnel Posted May 21, 2011 Author Share Posted May 21, 2011 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! Quote Link to comment Share on other sites More sharing options...
mkmDesign Posted May 21, 2011 Share Posted May 21, 2011 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"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.