Jump to content
Stef's Coding Community
narcis

php email

Recommended Posts

Can anyone explain me how to send an e-mail from a web, with php?

 

In Misc > functions: part2 Stefan Explains a bit the mail function. I try and it doesn't work for me. I get Email sent: 1, but I don't receive the email

 

- I attached the file: mail1.php:

$did_send = mail('info@mig-marketing.com','Subject','body of the message');

echo "Email sent: " . $did_send;

 

- I tried something more complex. But I don't receive the email either. mail2.php:

$to = "info@mig-marketing.com";

$subject = "Test mail";

$message = "Hello! This is a simple email message.";

$from = "narcis@mig-marketing.com";

$headers = "From:" . $from;

mail($to,$subject,$message,$headers);

echo "Mail Sent.";

mail1.php

mail2.php

Share this post


Link to post
Share on other sites

Where are you testing the mail() function? On your local computer using WAMP or MAMP? On a live web host?

 

If you are testing on your local computer, mail() tends not to work. It just depends on your setup... and may require you to modify your PHP.ini file to get it to work. I generally recommend testing mail() functionality on a live server rather than on your local computer.

Share this post


Link to post
Share on other sites

I'm in a Mac OS Lion (OS X 10.7.4)

I'm not worried about what OS your personal computer you are running, but what operating system your server is running, and whether the mail() function might be disabled.

 

And I'm assuming you've checked your spam box, correct?

Share this post


Link to post
Share on other sites

Can anyone explain me how to send an e-mail from a web, with php?

 

In Misc > functions: part2 Stefan Explains a bit the mail function. I try and it doesn't work for me. I get Email sent: 1, but I don't receive the email

 

- I attached the file: mail1.php:

$did_send = mail('info@mig-marketing.com','Subject','body of the message');

echo "Email sent: " . $did_send;

 

- I tried something more complex. But I don't receive the email either. mail2.php:

$to = "info@mig-marketing.com";

$subject = "Test mail";

$message = "Hello! This is a simple email message.";

$from = "narcis@mig-marketing.com";

$headers = "From:" . $from;

mail($to,$subject,$message,$headers);

echo "Mail Sent.";

 

narcis,

try simplifying the process a bit by using this code all by itself in a php page:

mail('youremail@gmail.com', 'This is My subject', 'This is the message', null,'-finfo@yourdomain.info');

 

I've always been able to use that on HostGator and most sites without a problem. I do have one host that disables the php mail function though, so it doesn't work with them.

Share this post


Link to post
Share on other sites

Shouldn't you enclose your mail function within an if statement if you want to test if it was accepted to be sent and echo out something whether true or false?

 

e.g.

$subject = "testing mail";

$message = "Here is a test mail message";

$to = "me@gmail.com";

$from = "me@gmail.com";

$header = "From: ".$from;

 

if(mail($to, $subject, $message, $header))

echo "Oh ya!<br>";

else

echo "well crap!<br>";

Share this post


Link to post
Share on other sites

Shouldn't you enclose your mail function within an if statement if you want to test if it was accepted to be sent and echo out something whether true or false?

 

e.g.

$subject = "testing mail";

$message = "Here is a test mail message";

$to = "me@gmail.com";

$from = "me@gmail.com";

$header = "From: ".$from;

 

if(mail($to, $subject, $message, $header))

echo "Oh ya!<br>";

else

echo "well crap!<br>";

 

Hi markvs,

It's much easier to just use the single line.. and check your email for success. :)

Share this post


Link to post
Share on other sites

Hi markvs,

It's much easier to just use the single line.. and check your email for success. :)

 

Hi Amy,

 

I agree, but by using the if statement, you would at least know if the email was being handed off to the mail server for delivery, whether delivered or not.

Share this post


Link to post
Share on other sites

Hi Amy,

 

I agree, but by using the if statement, you would at least know if the email was being handed off to the mail server for delivery, whether delivered or not.

 

True true! :) It's definitely an option!

Share this post


Link to post
Share on other sites
Guest jimcarry28

If you are testing on your local computer, mail() tends not to work. It just depends on your setup... and may require you to modify your PHP.ini file to get it to work. I generally recommend testing mail() functionality on a live server rather than on your local computer.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...