unable to send e-mail using my function - php

I am facing e-mail sending problem.
e-mail does not send through my e-mail function.
My code is given below:
ini_set("sendmail_from",$_POST['email']);
$to = 'email#gmail.com';
$subject = $_POST['subject'];
$from = $_POST['email'];
$message = $_POST['message'];
$message = wordwrap($message, 70);
mail($to,$subject,$message,$from);

You have to setup your SMTP mail server and mention those details in php.ini before executing your script. For further info, please check http://www.phpeasystep.com/phptu/23.html

In your code you have to set proper header,
you have used $from for header section of mail.
change its value as
$from= 'From: '.$_POST['email']. "\r\n" .
'Reply-To: '.$_POST['email'] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
or you can use below solution.
Use PHPMailer API for sending mail. all are inbuilt there.
download complete code form below link
PHPMailer API
goodluck

Related

Unable to sent an email using codeigniter

I have a codeigniter with tank auth configured.I was doing all the test and everything was running properly on my development server.I shiftwd all my codes to the productiom server and no activation email of tank auth is being sent.I used gmail cobfiguration in the email vodeingiter config and email was sent but to some emails its not being sent.Why im i unable to sent email using the default codeigniter settinga in the production server.please help
In the function where you sending you data afte completion of task
$email = 'email on which you want to send mail';
$Subject = "Your subject message";
$smsg = null;
$smsg = 'yor message';
$email_from = 'manishatutorsbureau#gmail.com';
$header = 'From: ' . $email_from . "\r\n" .
'Reply-To: ' . $email_from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// Start code for sending mail
mail($email, $Subject, $smsg, $header);

mail() method using PHP, how do I set the sender?

I'm using iPage for my website, and I'm using a simple mail() method to send test mails from my page. On iPage, I have email capabilities via mark#domain.com. But when I send an email out, it comes from the iPage server and is sent from ipg.domain#boscustweb3506.eigbox.net, which is quite ugly looking!
Is there a way I can use the mail() method in php to send an email from my page that will use the shorter sender above? Thanks for any and all help!
you need to add a header named From. this code will send with the mail address webmaster#example.com:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Try this, You can add the From header to customise the sender address.
$from ='mark#domain.com';
$headers = 'From: ' . $from . "\r\n";
...
mail($to, $subject, $message, $headers);

php can't send email

I have been trying to send a php contact form, but it's not working at all.
my xampp use 8080 port.
I though that I have to change some configuration on php.ini or httpd.conf as well.
Please anybody help me.
Thank you.
this is the script:
<?php
$to = "tiya.vort4#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to,$subject,$message,$headers)){
echo "Mail Sent.";
}
You would have to configure the mercury server bundled with xampp to actually deliver/relay the mails.

noreply#example.com not working (rackspace)

I'm trying to use noreply to send out emails, but it doesn't work - it wont sent anything. I am using this test-file:
<?php
$to = 'myemailhere';
$subject = 'You received an email message!';
$message = 'This is a message in the email body form.';
$headers = 'From: noreply#example.com' . "\r\n" .
'Reply-To: noreply#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
What could be the problem? By the way, I am using rackspacke, if anyone should know about it.
Thanks in advance!
If you're running on a Rackspace cloud server, you will have to configure the server yourself to be able to send mail. The mail() function relies on the OS configuration to handle emailing. If you are on a Rackspace cloud site, you will likely need to contact Rackspace support for help.
Personally I dodge this bullet altogether by using PEAR's SMTP class. This is a full SMTP implementation in PHP and since it does not rely on any outside configuration or module, it is fully portable. It has saved me a LOT of trouble.
http://pear.php.net/package/Mail
http://pear.php.net/package/Net_SMTP
Note: The PEAR site is having some loading issues atm for me. Give it a minute and it should load.
what is exception? use try catch block. Else try this code
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

PHP from field when sending mail()

I'm using PHP's mail() function and noticing that my mail is being shown from being sent by 'My Website' in my inbox, but when I click on the actual email it shows it being sent from mywebsite#sitename.localdomain.
Ideally I'd like to have it say being sent from 'My Website', but the reply email being 'no-reply#mywebsite.com', and not to have it say anything about #sitename.localdomain.
$to = trim(strtolower($_POST['to']));
$from = trim($_POST['from']);
$message = trim($_POST['message']);
$subject = $from . ' has shared a link with you';
$headers = 'From: My Website' . "\r\n" .
'Reply-To:' . $to . "\r\n" .
'X-Mailer: PHP/';
mail($to, $subject, $message, $headers);
Is this an issue that I need to fix in Apache, or can I modify the headers within PHP?
Try this:
$to = trim(strtolower($_POST['to']));
$from = trim($_POST['from']);
$message = trim($_POST['message']);
$subject = $from . ' has shared a link with you';
$headers = 'From: My Website <no-reply#mywebsite.com>' . "\r\n" . // <- change your email here
'Reply-To:' . $to . "\r\n" .
'X-Mailer: PHP/';
mail($to, $subject, $message, $headers);
The Question and Answer #1 contains a serious security vulnerability -
$to = trim(strtolower($_POST['to']));
Will allow an attacker to use your website to email arbitrary spam and your site will be blocked from most search engines.
See
https://www.owasp.org/index.php/Top_10_2010-A1
My recommendation is to
Sanitize the to and from fields
Never ever ever copy the message in the post to the output unless carefully sanitized.

Categories