Problem with mail() function.

the mail() function

Moderators: macek, egami, gesf

nunkstop
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Nov 10, 2011 7:37 pm

Problem with mail() function.

Postby nunkstop » Sat Nov 12, 2011 6:17 am

Hi everybody!

I have a question about mail() function. I used mail function to create form contact for my website, but it's not working. Because this is first time i use host premium and using php to create form contact so maybe i dont know how to config for it working.

I code it as follow :

Code: Select all

<?php
$to = youremail@host.com;
$mess = "This is message";
$subject = "test mail";
$header = "From : myemail@gmail.com";

if(mail($to, $subject, $mess, $header)){
  echo "Your mail has been send!";
}else{
 echo "Can not send your mail now! Plz try later.";
}
?>


That code just an example of mail function i used, not full of form.

It not work when i upload on my host.

and I tried another method to send mail , by using PHPmailer, but it's also not working.

I create two mail address of my host, and using it to send mail to gmail ---> it's work well, and from gmail to it ---> it's also work well.

But i can not use mail() to send mail from form contact.

Anyone could help me solve this problem? There is any config i should do for it working?

TheProdigyGuy
New php-forum User
New php-forum User
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Re: Problem with mail() function.

Postby TheProdigyGuy » Mon Dec 19, 2011 4:41 pm

Hello nunkstop.
Possible causes:

Code: Select all

$to = youremail@host.com;
$mess = "This is message";
$subject = "test mail";
$header = "From : myemail@gmail.com";


==============================
$header = "From : myemail@gmail.com";

Antispam system on your host + on gmail can detect it as Possible Email Spoofing
==============================
2) mail() function disabled for security reasons.(I saw a lot of hosting which disables it)
3) Wrong syntax $to = youremail@host.com;
Right $to ='youremail@host.com';
+ when sending your mails always use Return Path:
http://php.net/manual/en/function.mail.php
+
I create two mail address of my host, and using it to send mail to gmail ---> it's work well, and from gmail to it ---> it's also work well.

It is nothing to do with PHP on most cases it is Mailer Daemon and it send/accept mails directly not using PHP in this case.


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 3 guests

cron