jcafaro10 Posted May 20, 2008 Share Posted May 20, 2008 I'm trying to get a simple email form to work but it will not. Here is the code I'm using: <?php if(isset($_POST['submitted'])) { $to = 'myemailadd@gmail.com'; $from = 'someone@gmail.com'; $subject = 'tesing'; $body = 'testing'; if (mail ($to, $subject, $body, $from)) { echo 'MAIL - OK'; } else { echo 'MAIL FAILED'; } } ?> I want this email to go to myemailadd@gmail.com. I'm not sure if its going anywhere, but the MAIL - OK does come up Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/ Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 gmail requires authentication this is not mine but looks sound [ This explains how to use gmail to send emails in php using PHPMailer] 1 Download PHPMailer from http://phpmailer.sourceforge.net 2 Extract to folder phpmailer 3 Create a file email.php 4 Paste this code and change the values in blue as you need (I modified the sample code given on the PHPMailer homepage) <?php IsSMTP(); // send via SMTP $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "username@gmail.com"; // SMTP username $mail->Password = "password"; // SMTP password $webmaster_email = "username@doamin.com"; //Reply to this email ID $email="username@domain.com"; // Recipients email ID $name="name"; // Recipient's name $mail->From = $webmaster_email; $mail->FromName = "Webmaster"; $mail->AddAddress($email,$name); $mail->AddReplyTo($webmaster_email,"Webmaster"); $mail->WordWrap = 50; // set word wrap $mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment $mail->IsHTML(true); // send as HTML $mail->Subject = "This is the subject"; $mail->Body = "Hi, This is the HTML BODY "; //HTML Body $mail->AltBody = "This is the body when user views in plain text format"; //Text Body if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; } ?> 5 Open the file class.smtp.php in phpmailer directory 6 Paste this code $host = "ssl://smtp.gmail.com"; $port = 465; before the line 104 #connect to the smtp server Hint: Search for #connect 7 Open this page in browser and it will send the email using GMail. Hint: When you want to email the details from a form, set the variables using the form variables. eg. $mail->Username=$_POST['email'] Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546163 Share on other sites More sharing options...
jcafaro10 Posted May 20, 2008 Author Share Posted May 20, 2008 Wait so in order for someone to send me an email I need to know their password in my script? I don't think that's right. And what about other email providers? That seems strange Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546165 Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 your sending FROM a gmail account $from = 'someone@gmail.com';, thus you need your gmail password, if your not sending from a gmail account your need to check the your POP & SMTP setup in the php.ini file, to check they are your correct email server settings Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546167 Share on other sites More sharing options...
jcafaro10 Posted May 21, 2008 Author Share Posted May 21, 2008 I have a website hosted with FreeHostia. They allow php and email and all that. I don't want to send an email from someones email account to mine, I want my webpage to send an email to me, reporting what someones email address is. I want the $to part to be my email address b/c I want the email to go to me, and I want the from part to be, I guess, whatever it is that's sending me the email. Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546168 Share on other sites More sharing options...
MadTechie Posted May 21, 2008 Share Posted May 21, 2008 your probably need to open a ticket with FreeHostia, they seams to have a ton members with email problems see here Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546173 Share on other sites More sharing options...
jcafaro10 Posted May 21, 2008 Author Share Posted May 21, 2008 yea everything says to Open a ticket, which I've done. And my support guy told me to "find a suitable php script" but I'm pretty sure I'm not doing something totally wrong. Also he was able to get it to work and gave me his code which sort of worked but not really. He gave me this: <?php $from = 'From: YourName <myemail@mydomain.com>'; $to = 'support@freehostia.com'; $subject = 'Subject'; $body = 'TEST'; if (mail ($to, $subject, $body, $from)) { echo 'MAIL - OK'; } else { echo 'MAIL FAILED'; } ?> This gave me an email in my box but it shouldn't have because its supposed to be FROM me, TO support so idk why it worked. Also, is there something significant about having From: YourName and <> in sending an email in php? Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546177 Share on other sites More sharing options...
MadTechie Posted May 21, 2008 Share Posted May 21, 2008 if you have $from = 'From: YourName <myemail@mydomain.com>'; on the clients email app it will show YourName as whos it from but if you reply it goes to myemail@mydomain.com, when you setup your hosting account they should give you all the details to setup your email on your own email app (ie outlook) you could try <?php $from = "From: YourName <myemail@mydomain.com>\r\nReply-To: myGMAIL@gmail.com\r\n"; $to = 'support@freehostia.com'; //change to you freehostia email address $subject = 'Subject'; $body = 'TEST'; if (mail ($to, $subject, $body, $from)) { echo 'MAIL - OK'; } else { echo 'MAIL FAILED'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546188 Share on other sites More sharing options...
jcafaro10 Posted May 21, 2008 Author Share Posted May 21, 2008 It works if I make to: and from: the same address, aka my email address. I'll just have the email address that I want to respond to get sent in the subject or body. Now if only I wasn't getting kicked out of my account... Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546195 Share on other sites More sharing options...
MadTechie Posted May 21, 2008 Share Posted May 21, 2008 thats why i said try this $from = "From: YourName <myemail@mydomain.com>\r\nReply-To: myGMAIL@gmail.com\r\n"; note the "myGMAIL@gmail.com" can be any email and when they reply it will go their so it sends from the freehostia but they will reply to the gmail one Quote Link to comment https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/#findComment-546198 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.