I am using following php code but i ain't getting any mail
function Mail($to, $subject, $message)
{
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: MYAPP! <myYahooMail>' . "\r\n";
// Mail it
if(!mail($to, $subject, $message, $headers)) {
throw new Exception('There was a problem trying to send an email.');
}
}
The error you're getting is Fatal error: Cannot redeclare mail(). This is because
PHP has a built in mail function. Name your function something else.
You probably need to edit your php.ini (xampp\php\php.ini). Search for "mail function" and change these parameters according your server specs. If you are not the host, you can do this via htaccess.
SMTP = "Your server smtp address here"
smtp_port = 587
Related
I am a PHP-newbie. This is my code for sending an email with PHP.
mail("xxxx#gmail.com", "the subject", $message,
"From: webmaster#example.com \r\n"
."X-Mailer: PHP/" . phpversion());
You can find it here in php sandbox:
http://sandbox.onlinephpfunctions.com/code/88e1df4ddf90cdf64d5e04c2c2da4c10dfb801ee
But it doesn' work.
Do I need to setup an SMTP connection? If so, how?
Yep, SMTP is more stable method;
Just use https://github.com/PHPMailer/PHPMailer
Please try this code, and if you would like to run this code in Localhost then you have to Configure SMTP details in PHP.ini. this code will run in Live hosting without any error, you can also design HTML Message with this code.
$to_email='xxxx#gmail.com'
$email="webmaster#example.com";
$headers = "From: ".$email."\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$subject = 'Demo Mail';
$message = 'Your Message'
mail($to_email,$subject,$message,$headers);
Mail function now not working my server. i cannot find out the solution for that. i am getting bellow this error when i submitting the contact form.
Warning: mail() [function.mail]: SMTP server response: 550 Sender is not allowed. in E:\HostingSpace\abayamtranslations.com\httpdocs\contact-form\classes\contact.php on line 137
ERROR! Please ensure PHP Mail() is correctly configured on this server.
$address = "info#abayamtranslations.com";
ini_set("SMTP","mail.abayamtranslations.com");
ini_set("smtp_port","25");
ini_set('sendmail_from','info#abayamtranslations.com');
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
Try with the following
$emailFrom = "info#abayamtranslations.com"; // match this to the domain you are sending email from
$email = "example#example.com";
$subject = "Subject of email";
$headers = 'From:' . $emailFrom . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;
$message = "Message of email";
mail($email, $subject, $message, $headers);
"550 Sender is not allowed" means that the SMTP Blocked Senders list rejected the sender. Search your SMTP log for 550 Sender is not allowed and figure out what address is getting blocked and then alter your list to let that through.
That is the meaning of the error you are getting. This is from the hMailServer Documentation.
Can you try if the following will work?
<?php
mail('info#abayamtranslations.com','Test Email','This is a test email.',"From: info#abayamtranslations.com");
?>
If it doesn't work, then it's probably due to a misconfiguration in your hMailServer and you would need to check your hMailServer Logs.
You are on the windows server, hence forth you have to change SMTP of windows server.
Better way is to use PHPMailer Library. https://github.com/PHPMailer/PHPMailer
Some important information is missing under your SMTP configuration....
username and password is needed to authenticate with the SMTP mail server.....
it easy ti use smtp mailing in php with:
PHPMailer (https://github.com/Synchro/PHPMailerhttps://github.com/Synchro/PHPMailer)
have a look into it....
Thankyou....
$mailto = 'example#mail.com';
$subject = 'foo';
$message = 'bar';
mail($mailto, $subject, $message);
I open with the mail with OUTLOOK 2010, it display normally. But the mail has an attachment named "mail.html" that display "bar" when I open it in foxmail.
What is difference between these mail client? So this problem isn't seem a programming problem.
Did you use any headers?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
Don't use foxmail so no clue if it works...but if you didn't send headers it's worth a try.
I have tried the following with little success:
$fromEmail = "something.com <noreply#something.com>\r\n";
$headers = 'From: '.$fromEmail;
$headers .= 'Reply-To: '.$fromEmail;
$headers .= 'Return-Path: '.$fromEmail;
$headers = 'MIME-Version: 1.0' . '\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
if(mail($to, $subject, $message, $headers)) { echo "1"; exit; }
I have tried commenting out the Reply-To: and Return-Path: lines as well as replacing the if(... line with:
if(mail($to, $subject, $message, $headers,'-fnoreply#something.com')) { ...
In all cases the email arrives but is from anonymous#...
There is a syntax error in your code.
You are missing a dot in MIME header line.
should be:
$headers = 'From: '.$fromEmail;
$headers .= 'Reply-To: '.$fromEmail;
$headers .= 'Return-Path: '.$fromEmail;
$headers .= 'MIME-Version: 1.0' . '\n';
<...>
It looks like anonymous#... is your envelope "from" address. The envelope "from" address is different from the address that appears in your "From:" header of the email. It is what sendmail uses in its "MAIL FROM/RCPT TO" exchange with the receiving mail server.The main reason it is called an "envelope" address is that appears outside of the message header and body, in the raw SMTP exchange between mail servers.
To change the envelope "from" address on unix, you specify an "-f" option to your sendmail binary. You can do this globally in php.ini by adding the "-r" option to the "sendmail_path" command line. You can also do it programmatically from within PHP by passing -f mail#something.com as the additional parameter argument to the mail() function (the 5th argument).
In the php.ini you can add default from address like this
sendmail_from = me#something.com
To change the envelope mail from, you can use the fifth argument. This is used for options that should be passed directly to sendmail. Here, you should add -f info#mywebaddress.com. A simple example is shown below.
mail('recipient#domain.com', 'Subject', 'Message',
'From: info#myaddress.info','-f info#myaddress.info');
And also, all of this is mentioned in the official PHP manual on mail().
Im having some problems sending mail. I have a ubuntu server running postfix as mailserver. The webapp is based on symfony 1.2 and has Swift 3 for mailing. Everyrhing is running on the same server. This is the code im trying to run:
public static function sendMailLocal($mailFrom, $mailto, $subject, $mailBody, $prevError)
{
$mailer = null;
try
{
$connection = new Swift_Connection_SMTP('localhost', '25');
$mailer = new Swift($connection);
// Create the mailer and message objects
$message = new Swift_Message($subject, $mailBody, 'text/html');
// Send
$mailer->send($message, $mailto, $mailFrom);
$mailer->disconnect();
}
catch (Exception $e)
{
if($mailer != null)
$mailer->disconnect();
throw new EmailTransferException ("There was an error while trying to send the email - locally:" . $e->getMessage() . " , first error:" . $prevError);
}
}
This is the error message im getting:
There was an error while trying to send the email - locally:The SMTP connection failed to start [localhost:25]: fsockopen returned Error Number 111 and Error String 'Connection refused' ,
It's kind of strange, because i did manage to send a mail without swift with this code:
//adresses are examples
$to = "john.doe#mail.com";
$sender_email = "someone#mail.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: <'.$to.'>' . "\r\n";
$headers .= 'From: John Doe<'.$sender_email.'>' . "\r\n";
// Mail it
$success = mail($to, "test from server", "msg", $headers);
Anybody got any ideas about this??
thanks!
It's not a problem with Symfony or PHP - your local SMTP server is unreachable. You likely have a configuration problem with your mail server that is preventing the SMTP server being available on it's native port (25).