Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/106547-cant-get-simple-email-to-work/
Share on other sites

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']

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

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. 

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?

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';
}
?>

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

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.