E-mail function not working on website - php

I have a contact page uploaded at this site. This URL is working properly, there are no errors or warnings except send mail function is not working.
When I test it in on our testing server it works properly, I can send and receive the mail.
Can you provide any assistance with this please?
$to = $_POST['email'];
$subject = $_POST['subject'];
$headers = 'From: info#mdpharma.se' . "\r\n" . 'Reply-To: info#mdpharma.se' . "\r\n" ;
$message =$_POST['message'];
$message = wordwrap($message, 70, "\r\n");
if($_POST['email']){
mail($to, $subject, $message,null,'-fwebmaster#example.com');
echo "Mail is successfully sent to you";
} else {
echo "Mail is not set to you";
}

you can take help from here http://phpmailer.worxware.com/index.php?pg=exampledb .
everything is well explained in here. best of luck.

Related

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.";

Sending Email in php, headers problems

I trying to send email using mail() function...
here is my code:
<html>
<form action ="" method ="post">
<input type="submit" name= "email" value="email">
<form>
<?php
if (isset($_POST['email']))
{
mail("receiver#hotmail.com", "Subject: Hi", "hello" );
echo "Mail Sent";
}
?>
</html>
the code about works just fine, I can get the email but the only problem was when I check the email, the sender will be "webmaster#something.org"
I tried to change the code to:
mail("receiver#hotmail.com", "Subject: Hi","hello", "From: sender#yahoo.com" );
but it didn't work...
Could you please help me to include the name of the person who sent the email...
Thank a lot
Please try this.It is the simplest method to mail someone.
<?php
$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);
?>
Check php mail manual.
You need to define 'From: xxx' in the header
check your form tag closed or not?
<?php
$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.";
?>
Use [phpmailer to send the mail.
You can set the sender id and content type for the mail.

sending a email by the use of a variable

I have search for my problem and i know there is a easy fix for it but i just can't figure it out and i keep banging my head against the wall, so here goes:
i have a variable in my config file
$businessemail = "me#myemail.com";
This email changes a lot so i want to use this variable in my mail script which is this
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = '$businessemail'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
Now my question is how do i format the $businessemail in the right way so it can read and sent the message to the email in the config file
Thanks for the help.
$emailTo = $businessemail; // don't use variable in single quotes here

PHP E-Mail Form w/Options

I need to include the first code (which calls the e-mail from a WordPress options panel) in the second code where it says email#mail.com. I tried to include " around the code, but it doesn't seem to work. I also tried to strip slashes, but to no avail.
How I call the e-mail
<?php echo get_option('to_email'); ?>
The relevant part of my contact form:
if(!isset($hasError)) {
$emailTo = 'email#mail.com';
$subject = 'Contact Form Submission from '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailTo = get_option('to_email');
You have to make sure the right files are included (wordpress config files).

php mail function

<?php
$sendto = "account#gmail.com";
$subject = "email confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc...";
# send the email
mail($sendto, $subject, $message);
?>
this is the code that i wrote to test mail function on localhost.
i have ran the script in browser for several times and still dun receive any email in my mail box.
Do I need any additional configurations?
thx in advance!
Basically is hard to send a mail from localhost to any mail providers.
They have big restrictions on the incoming mails, and the simply mail() won't work.
You need to use an SMTP server.
and define that server in php configuration
smtp = localhost #(here should be your smtp server)
smtp_port = 25
if you don't have an SMTP server, try to pass all headers like in PHP examples:
$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);
http://www.php.net/manual/en/function.mail.php
You need to make sure that you have your PHP installation set up to use a working SMTP Server. You might find what you're looking for in answers to this question. Failing that you'll likely need to test your script on your live web server.
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'yourname#yourwebsite.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message"
?>
<?php
$to = "inspiretechpark#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "name1#website-name.com, name2#website-name.com,name3#website-
name.com";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "name1#website-name.com, name2#website-name.com,name3#website-
name.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
$headers .= "Cc: someone#domain.com \r\n";
$headers .= "Bcc: someoneelse#domain.com \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
Try This Guys..This Is For Sending Mail
Try this:
<?php
$sender = 'email#example.com';
$recipient = 'email#example.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
If you are working with localhost then, i hope it will never work. It will work only on a mail configured server. Please try on it.

Categories