I was trying to use the mail function and i tried playing with this from the php documentation from php.net and I do not believe this is working
houldn’t it sent an email to the address I have provided it and then output “Mail sent”?
When I save it as mail.php, uploaded it to my server, and point my browser to it here: http://www.the-irf.com/mail.php
it echos Mail sent, but I never get an email.
Do you have any ideas on why this may be happening, the code is below:
<?php // The message $message = “Line 1\
Line 2\
Line 3”;
// In case any of our lines are larger than 70 characters, we should use wordwrap() $message = wordwrap($message, 70);
// Send mail(‘theirf@gmail.com’, ‘php mail’, $message);
echo”Mail sent”; ?>
I would appreciate any help regarding using the mail function properly or anything to help me with my issue very much.
oh wow, i forgot to clsoe the comments. That ahs got to be the stupidest coding mistake I have evr done.
However, I typed this new one without comments and I am still not reciving an email?
Is this proper syntax:
This is all that is in the mail.php file:
<?php
$to = 'theirf@gmail.com';
$subject = 'You have PHP mail!';
$message = 'This email was sent via PHP';
mail($to, $subject, $message, $headers);
echo "The email was sent succesfully!";
?>
Maybe should I remove the php brackets because there is only php in this document?
Or are there any other problems you may see with my code.
your IF block looks ok. the only “technical” change I would suggest is to use === instead of ==.
regarding the headers, I can’t tell for sure without actually running the code.
if you click the mail link in my previous post it will take you to the php online manual on mail() where it has some really good example code on building headers and running mail().
<?php
$to = 'theirf@gmail.com';
$subject = 'You have PHP mail!';
$message = 'This email was sent via PHP';
$headers = 'From: [email]webmaster@example.com[/email]' . "\\r\
" .
'Reply-To: [email]webmaster@example.com[/email]' . "\\r\
" .
'X-Mailer: PHP/' . phpversion();
mailResult=mail($to, $subject, $message, $headers);
if($mailResult===true)
{echo "Message was sent successfully";}
else
{echo "Message was not submitted successfully";}
?>
And the headers part should be valid accoridng to the .mail() PHP manual because I copied the line $headers=… from that manual.
However, I am now getting a PHP error that says: Parse error: syntax error, unexpected ‘=’ in /home/irfan/www/mail.php on line 8
Any idea why executing the mail function and setting it equal to the variable mailResult, which is what I am pretty sure line 8 is would cause this error?
You can see it for yourself, I have uploaded the php file here
Wow today is just filled with stupid coding mistakes. So I corrected the php code
and the if statement caused the echo of “The mail was sent successfully”
but I am still not receiving anything in my inbox.
How would I approach enabling SMTP. I know I could always :google: it but
but I was wondering if you could give me a more helpful procedure in accomplishing this.
in my web hosting account smtp being enabled is a “feature” and not something I can control via the control panel. all I see in the cp is that it is switched on.
if you can’t switch it on directly in your hosting account (and I doubt you would be able to unless you are an admin person) contact your hosting account’s support people and ask them if you are entitled to have smtp enabled on your account.
Hey Kalon,
My friend who owns the sever says that he can not enable smtp due to some restrictions by or something regarding at&t who provides the internet for said server.
Specifically he said in a SMS,
“It’s (STMP being enabled) not and thanks to AT&T messing with port 25 it can’t be.”
Does this make sense?
Do you have any other solutions or advice so that I can get the email to send.
if you can’t have smtp enabled then afaik php mail() is not an option for you.
Do you have any other solutions or advice so that I can get the email to send.
to be honest, not off the top of my head.
all I can suggest is try googling “sending emails using php” and you might be able to use one of the 3rd party email applications available that do not require smtp.
What is bothering me however is that once a few months ago the php mail worked on both my server and test server.
My test server is ran by MAMP test server for Mac. I wonder if there is any way I can enable stmp on a test server? Is it possible?
I am using XAMPP (a windows equivalent to MAMP) and this is what I do to send emails from XAMPP for testing/development purposes. the concept for MAMP should be similar.
I use ini_set() to set the value of the “SMTP” variable in php.ini (xampp’s php configuration file) to the name of the smtp mail server of my real world personal email address.
I use ini_set() to set the value of smtp_port in php.ini to 25
I set the From: header (a must have for php mail) to my real world personal email address.
the above ini_set’s are added just above your mail() statement in your php script.
While testing my mail function under XAMPP, I must also have a connection to the www established as well because in essence I am sending my test emails from my real world email address.
I was looking online and could not find any documentation on the location of the php.ini file in the MAMP files.
I assumed there was either one natively or the usr had to write their own, which I am assuming can be done in a simple text-editor and saving the file as php.ini in the site’s root.
I am a little confused on what I should exactly have typed in the file.
What does your php.ini file have in it?
Also, is there any other general configurations or settigns that should be in all PHP.ini files that I should have if I am going to create my own in a text editor and save in in the testServer’s root?
Thank you for all your help so far by the way.
I hope that you can help me know what exactly I have to type in the file so I can get to developing the mail script I was working on. And thank you for helping me with fine-tuning said mail script as well.
Wow, I serious did not see that on the Google Results err or at least I do not remember seeing it.
Thank you.
I found in the php.ini file:
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = [email]me@example.com[/email]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
and I changed the following:
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
[B];sendmail_from = [email]me@example.com[/email][/B]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
the port number was already t 25, but what should I change the SMTP to? I know the the name of my smtp mail server? Is it my test server, err or is it gmail because that is when the sending email address is at?
Does doing this enable smtp or do you know of anything else I have to change? Like is there Boolean value for the hypothetical variable $SMTP_enabled that I change to true?