PHP Mailer error using Go Daddy - php

mailPlease help. My PHP mailer is not working that I host on Go Daddy. Any idea why the email won't send?
<?php
session_start();
$contact=$_POST['contact'];
$phone=$_POST['telephone'];
$email=$_POST['email'];
$msg=$_POST['message'];
$to="webform#xxx.com";
$subject="Contact Form";
$from=$email;
$message .= '<table border="1px" width="50%" style="border:1px black solid;margin:0px auto">';
$message .= '<tr><th colspan="2" style="text-align:center">Contacts Information</th></tr>';
$message .= '<tr><td>Name :- </td><td>'.$contact.'</td></tr>';
$message .='<tr> <td>Phone No. :- </td><td>'.$phone.'</td></tr>';
$message .= "<tr><td>Email :- </td><td>" . $email . "</td></tr>";
$message .= "<tr><td>Message :- </td><td>" . $msg. "</td></tr>";
$message .= "</table>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
mail($to, $subject, $message, $headers);
header("Location: sent.html");

Their is a typo error in your code.
$contact=$_POST['contact'];
$phone=$_POST['telephone'];
$email=$_POST['email'];
$msg=$_POST['message'];
$to="webform#xxx.com";
$subject="Contact Form";
$from=$enm; //this should be $from=$email
CAUTION: ur not validating user input. Pls do validate them server side to avoid errors and attack attempts.
If u have any other error pls state it clearly.

Related

How do I paste a image on a email message

Oke, this is a tricky one. (I think).
Do you know when you receive a message and the email has a image on top or on the bottom of the page.
I have been trying to make it but can't figure it out.
I hope you guy's can help me with this problem.
This is what I got so far;
<?php
$to = 'info#gmail.com';
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$gast = $_POST['email'];
$tmpName = $_FILES['attachment']['tmp_name'];
$fileType = $_FILES['attachment']['type'];
$fileName = $_FILES['attachment']['name'];
if(empty($errors))
{
$to = $to;
$from = $gast;
$file = fopen($tmpName,'rb');
$data = fread($file,filesize($tmpName));
fclose($file);
$mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";
$body = "E-mail".
"Name: $name\n".
"Email: $gast \n".
"Content-Type: {$fileType};\n".
"Content-Transfer-Encoding: base64\n\n".
$data;
$headers = "From: $from \r\n";
$headers .= "Email: $gast \r\n";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative;\n";
$headers .= " boundary=\"{$mimeBoundary}\"";
$headers .= "img src='http://cache.estivant.nl/image/1399025430_12_banners-bestemmingen-single-1680x460-extra2-06-kos_1399025430.jpg' alt='image'";
$data = chunk_split(base64_encode($data));
mail($to, $body, $headers);
}
}
?>
<html>
<head></head>
<body>
<form method="post" action="">
<label for="name">name</label>
<input type="name" name="name" value="" />
<label for="email">email</label>
<input type="email" name="email" value="" />
<button id="submit" name="submit">send</button>
</form>
</body>
</html>
Simply write a html page with css styles and format your email accordingly and use the html as your email body. This will create an image in the mail
<img src="image.jpg" alt="image"></img>
Please be aware that most (if not all) email clients will block your image from being showed to your receiver as long as you are not in their trusted sender list or contact list.
Of course, your email has to be sent as html
Here is an example of a nicely formatted email with images.
Note image syntax: <img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />'
$to = 'bob#example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
$message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
$message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
$message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
$addURLS = $_POST['addURLS'];
if (($addURLS) != '') {
$message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>";
}
$curText = htmlentities($_POST['curText']);
if (($curText) != '') {
$message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
}
$message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
Code source and full explanation: http://css-tricks.com/sending-nice-html-email-with-php/

mail is not sending to my site to godaddy workspace

<?php
if($_REQUEST['submit']=='SEND'){
$to= 'info#mysatoristudio.com,aespino#brainwaveadvertising.com,sales#mpsinfoservices.com,tamali#mpsinfoservices.com,tathagata#mpsinfoservices.com,tamali#mysatoristudio.com';
/* $to='ananya#mpsinfoservices.com';*/
$mailmessage = '
<html>
<head>
<title>Contact Us</title>
</head>
<body>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">
</td>
<tr>
<tr>
<td colspan="2">You have Successfully registerd for "Satori studio"</td>
</tr>
<tr>
<td colspan="2">Your Name : '.$_REQUEST['name'].'</td>
</tr>
<tr>
<td colspan="2">Your mail ID : '.$_REQUEST['email'].'</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</body>
</html>
';
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
/* $headers .= "Content-type: text/html; charset=iso-8859-1"."\r\n";*/
$headers .= "From: Satori studio <info#mysatoristudio.com>" . "\r\n";
$subject = 'Registration for "Satori studio"';
mail($to,$subject,$mailmessage,$headers);
header("Location:index.php?msg=seccess");
}
?>
The mail is sending from my site to every mail server like google,yahoo etc...but not in godaddy workspace mail id...is this a coding problem???or others...Please suggest...
I got this to work by adding
ini_set('SMTP', "relay-hosting.secureserver.net");
ini_set('smtp_port', "25");
before calling the mail function, as follows :
public function sendEmail( $text , $subject , $name , $sender_email , $destination )
{
$headers="From:$name <$sender_email>\r\n";
$headers .= "Reply-To: $sender_email\r\n";
$headers .= "Date: " . date("r") . "\r\n";
$headers .= "Return-Path: $sender_email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Message-ID: " . date("r") . $name ."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "Importance: High\r\n";
$headers .= "X-MXMail-Priority: High\r\n";
$headers .= "X-Mailer: PHP Mailer 1.0\r\n";
ini_set('SMTP', "relay-hosting.secureserver.net");
ini_set('smtp_port', "25");
mail( $destination , $subject , $text , $headers );
return true;
}
I also noticed that the mail only sends when using charset=iso-8859-1,
I think there might be something missing in the server configuration on godaddy workspace where it is not allowing utf-8 charset through mail. I think the support might help in this case if you really need the utf-8 charset.

Form submission and mail send

I have made a form for registration by php .The form has submitter email address field.I want that after form submission , form content will send to both form submitter and admin via submitter email address and admin email address. Submitter email address will get from submitter email address field.Admin email address is fixed .
For Submitter
headers= "from : no-reply#eschool.com"
messagebody same as it is
For admin
headers=" from :$email"
messagebody same as it is
I tried to do this:
Html code:
<form action="action.php" method="post">
<table>
<tr>
<td>Name</td>
<td>:</td>
<td><input type="text" name="name" width="400" /></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><input type="text" name="address" width="400" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="text" name="email" width="400" /></td>
</tr>
<tr>
<td>Password</td>
<td rowspan="2"> </td>
<td>
<p><input type="text" name="pass" width="400" /></p>
<p> </p>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="insert" value="Insert" /></td>
</tr>
</table>
<input type="submit" value="submit" />
</form>
action.php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$to = $email . "," . $admin;
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/plain;charset=UTF-8;" . "\n";
$headers .= "content-Transfer-encoding: 8bit" ."\n";
$headers .= "From: no-reply#eschool.com ". "\n";
mail($to, $subject, $email_message, $headers);
Thanks
Your code is perfect, what is your are facing problem, plz write your problem.
Make following change in action.php for your convenience :
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
//$to = $email $admin;
$email_message = '';
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers1 = 'MIME-Version: 1.0' . "\r\n";
$headers1 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers1 .= "From: no-reply#eschool.com ". "\n";
$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers2 .= "From: ". $email . "\n";
if(#mail( $email, $subject, $email_message , $headers1 )) {
#mail( $admin, $subject, $email_message , $headers2 )
echo "Mail Sent.";
} else {
echo "Mail Not Sent.";
}
?>
You can simply make two different versions of your headers and execute mail(...) twice:
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$email_message = "Name: ".$name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type:text/plain;charset=UTF-8;\n";
$headers .= "content-Transfer-encoding: 8bit\n";
$poster_headers = $headers . "From: no-reply#eschool.com\n";
$admin_headers = $headers . "From: ".$email."\n";
mail( $admin, $subject, $email_message, $admin_headers );
mail( $email, $subject, $email_message, $poster_headers );
?>

HTML formatted email does not display correctly

I'm still struggling with this mail script - I'm now getting all the marked up html through rather than seeing it as rendered html if that makes sense?
<?php
$mailheader .= "MIME-Version: 1.0\r\n";
$mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$formcontent .="<table border='1'>";
foreach ($_POST as $field=>$value)
{
$formcontent.="<tr>";
$formcontent .= "<td>$field:</td> <td>$value</td>";
$formcontent.="</tr>";
}
$formcontent .= '<tr><td>User-Agent: </td><td>'.$_SERVER['HTTP_USER_AGENT'].'</td>';
$formcontent .="</table>";
$recipient = "info#*******.com";
$subject = "Event feedback form";
$mailheader = "From: web.form#*******-events.co.uk\r\n";
$mailheader .= "Reply-To: $email\r\n";
$mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Failure!");
header("location:http://www.******-events.co.uk");
?>
Follow php's documentation:
You'll need html tags
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// 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: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
I'd rather use a PHP class as PHPMailer for HTML emails. And btw I will add the full HTML document tags (html, head, body, etc...) for the mail body.
I'd missed these:
$formcontent = '<html><body>';
Thanks for everyone's time and input though
Jim

Why doesn't this php mail script work?

I made a php script that sends mail. It worked fine until i changed it so it sent stuff as html instead of just plain text. However, it isn't working. The script itself returns a success, but I'm not getting the email. I've checked my spam folder. Could anyone see why this isn't working? Thanks
<?php
$to = $_POST["mail"];
$subject = 'Registration at Campatet';
$message = '
<html>
<head>
<title>Registration at Campatet</title>
</head>
<body>
<p>Thank you for registering at Campatet!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: no-reply#campatet.com" . "\r\n";
if(mail($to, $subject, $message, $headers)){
echo "Success sending e-mail to: <b>".$to."</b>";
}
else{
echo "There was a error";
}
?>
Use this as your only header:
$headers = "Content-type: text/html; From: no-reply#campatet.com";
First, try removing the line
$headers = "MIME-Version: 1.0" . "\r\n";
Are you sure that the post variable is receiving it's address correctly? Try removing that and replacing it with the email address you are trying to use.
Have you ever been able to successfully send mail from your website at all?
Specifying email headers without a Reply-To header is often considered as reason to suspect spam. It doesn't matter that you don't want replies, just specify the Reply-To header.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= 'From: no-reply#campatet.com' . "\r\n" . 'Reply-To: no-reply#campatet.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

Categories