E-mail In PHP

jspcodes

New Member
Messages
60
Reaction score
0
Points
0
Hello

I am urgently in need of sending E-mail in PHP. I have been using mail function for long time. But the mail is going inside spam in yahoo. How to avoid this one. Do you have code for using gmail smtp or can i use the smtp of x10hosting.com or mail function in php can be corrected by adding more headers. If any one knows the correct working code, please post it. Thank you in advance. Sorry for my poor English.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
It often happens automaticly send mail is seen as spam because the domain and the server that does the actual sending don't match. (for example, me@thissite.com that's actually send from anothersite.com)
So you could try to make the sending e-mail correspond to the sending server.
 

jspcodes

New Member
Messages
60
Reaction score
0
Points
0
It often happens automaticly send mail is seen as spam because the domain and the server that does the actual sending don't match. (for example, me@thissite.com that's actually send from anothersite.com)
So you could try to make the sending e-mail correspond to the sending server.

Sir we can solve this problem of mail getting into spam. i have programmed in JSP where mail goes directly to inbox where i use gmail smtp. I think mail function is insecure because it has less header so yahoo treats as spam. I think if we use even x10hosting smtp we can overcome the problem.

Help me.
 

mattura

Member
Messages
570
Reaction score
2
Points
18
To reduce the chances of being marked as spam, send lots of (proper) headers!
Specifically, X-Mailer and Message-ID:
PHP:
$headers="Message-ID: <".mktime()."@".$_SERVER['SERVER_NAME'].">\r\n";
$headers.="X-Mailer: PHP v".phpversion()."\r\n";
$headers.="Content-Type: text/html; charset=iso-8859-1\r\n"; //your char set here
mail($to,$subject,$body,$headers);
I couldn't tell you if this works for Yahoo! mail, but it did stop my messages going into Hotmail's spam box.
 

phpasks

New Member
Messages
145
Reaction score
0
Points
0
Sir we can solve this problem of mail getting into spam. i have programmed in JSP where mail goes directly to inbox where i use gmail smtp. I think mail function is insecure because it has less header so yahoo treats as spam. I think if we use even x10hosting smtp we can overcome the problem.

Help me.

You can used phpmailer function sent mail to yahoo then see it.

90% problem solved.

PHP:
<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->From     = "list@mydomain.com";
$mail->FromName = "List manager";
$mail->Host     = "smtp1.site.com;smtp2.site.com";
$mail->Mailer   = "smtp";

@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query  = "SELECT full_name, email, photo FROM employee WHERE id=$id";
$result = @MYSQL_QUERY($query);

while ($row = mysql_fetch_array ($result))
{
    // HTML body
    $body  = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
    $body .= "<i>Your</i> personal photograph to this message.<p>";
    $body .= "Sincerely, <br>";
    $body .= "PHPMailer List manager";

    // Plain text body (for mail clients that cannot read HTML)
    $text_body  = "Hello " . $row["full_name"] . ", \n\n";
    $text_body .= "Your personal photograph to this message.\n\n";
    $text_body .= "Sincerely, \n";
    $text_body .= "PHPMailer List manager";

    $mail->Body    = $body;
    $mail->AltBody = $text_body;
    $mail->AddAddress($row["email"], $row["full_name"]);
    $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

    if(!$mail->Send())
        echo "There has been a mail error sending to " . $row["email"] . "<br>";

    // Clear all addresses and attachments for next loop
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
?>

also you can see here - http://phpmailer.codeworxtech.com/examples.html
download - http://phpmailer.codeworxtech.com/sf.html?p=dl
 

jspcodes

New Member
Messages
60
Reaction score
0
Points
0
You can used phpmailer function sent mail to yahoo then see it.

90% problem solved.

PHP:
<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->From     = "list@mydomain.com";
$mail->FromName = "List manager";
$mail->Host     = "smtp1.site.com;smtp2.site.com";
$mail->Mailer   = "smtp";

@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query  = "SELECT full_name, email, photo FROM employee WHERE id=$id";
$result = @MYSQL_QUERY($query);

while ($row = mysql_fetch_array ($result))
{
    // HTML body
    $body  = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
    $body .= "<i>Your</i> personal photograph to this message.<p>";
    $body .= "Sincerely, <br>";
    $body .= "PHPMailer List manager";

    // Plain text body (for mail clients that cannot read HTML)
    $text_body  = "Hello " . $row["full_name"] . ", \n\n";
    $text_body .= "Your personal photograph to this message.\n\n";
    $text_body .= "Sincerely, \n";
    $text_body .= "PHPMailer List manager";

    $mail->Body    = $body;
    $mail->AltBody = $text_body;
    $mail->AddAddress($row["email"], $row["full_name"]);
    $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

    if(!$mail->Send())
        echo "There has been a mail error sending to " . $row["email"] . "<br>";

    // Clear all addresses and attachments for next loop
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
?>
also you can see here - http://phpmailer.codeworxtech.com/examples.html
download - http://phpmailer.codeworxtech.com/sf.html?p=dl

Your close to the solution. But this is not the exact solution. If we use SMTP with authentication then we can clearly overcome all problems even yahoo or hotmail. Gmail gives free smtp with authentication of gmail username and password can be used for this too. And the default port 25 is not used. Instead 465 should be used. I don't know the exact syntax in php. i have only jsp code.
 

jspcodes

New Member
Messages
60
Reaction score
0
Points
0
Problem solved. Thanks a ton man. But it only works with yahoo. Not good enough to get bid rid of hotmail.


<?php

include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer();

$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);

$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server

$mail->Username = "yourusername@gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password

$mail->AddReplyTo("yourusername@gmail.com","First Last");

$mail->From = "name@yourdomain.com";
$mail->FromName = "First Last";

$mail->Subject = "PHPMailer Test Subject via gmail";

//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap

$mail->MsgHTML($body);

$mail->AddAddress("whoto@otherdomain.com", "John Doe");

$mail->AddAttachment("images/phpmailer.gif"); // attachment

$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

?>
 

mattura

Member
Messages
570
Reaction score
2
Points
18
That's all very well if you trust that program not to store your password or abuse your account etc.
But if like me you don't trust anything you didn't make yourself, you probably want to stick with mail();
To add to my earlier points, make sure you give an email address in the 'From' header which is on the domain you send the mail from:
PHP:
 $headers ="From: MYWEBPAGE <ME@MYDOMAINNAME.COM>\r\n";
 $headers.="Content-Type: text/html; charset=iso-8859-1\r\n";
 $headers.="Message-ID: <".mktime()."@".$_SERVER['SERVER_NAME'].">\r\n";
 $headers.="X-Mailer: PHP v".phpversion()."\r\n";
 mail($to,$subject,$body,$headers);
The above code does not get filtered into my hotmail spam, it goes to my inbox.
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
That's all very well if you trust that program not to store your password or abuse your account etc.
But if like me you don't trust anything you didn't make yourself, you probably want to stick with mail();
To add to my earlier points, make sure you give an email address in the 'From' header which is on the domain you send the mail from:
PHP:
 $headers ="From: MYWEBPAGE <ME@MYDOMAINNAME.COM>\r\n";
 $headers.="Content-Type: text/html; charset=iso-8859-1\r\n";
 $headers.="Message-ID: <".mktime()."@".$_SERVER['SERVER_NAME'].">\r\n";
 $headers.="X-Mailer: PHP v".phpversion()."\r\n";
 mail($to,$subject,$body,$headers);
The above code does not get filtered into my hotmail spam, it goes to my inbox.

Uhm... First of all... it's a part of php, it's not 3rd party software... Second, you could create a new gmail account just for that purpose...
 

ciril tomy

New Member
Messages
53
Reaction score
1
Points
0
Happy news for all those who had problem between hotmail and php!!!

Hi, Everyone
:cool:PLEASE CHECKOUT THIS POST ALL THOSE WHO HAD PROBLEM BETWEEN HOTMAIL AND PHP.

Even I had the problem but believe me, it's working 100%
I am using this a simple "PHP" form.

Try out this....

Here is the HTML I used for my Contact Page http://www.webworld.x10hosting.com/contact.html

HTML
HTML:
<form action="contact.php" method="post" enctype="application/x-www-form-urlencoded">
  <p>
    <label>Name:</label>
    <input name="name" type="text"  id="name" />
  </p>
  <p>
    <label>Email:</label>
    <input name="email" type="text"  id="email" />
  </p>
    <p>
    <label>Subject:</label>
    <input type="text"  name="subject" />
  </p>
  <p>
    <label>Your Message:</label>
    <textarea rows="8" cols="30" name="message"></textarea>
  </p>
  <p>
    <input type="submit" class="button" value="Submit" />
    <input type="reset" class="button" value="Clear" />
    <input name="hiddenField" type="hidden" id="hiddenField" value="mailto:"putyour-email here@hotmail.com" />
  </p>
</form>
Now add this PHP
PHP:
<?php
$contact_name = $_POST['name'];
$contact_email = $_POST['email'];
$contact_subject = $_POST['subject'];
$contact_message = $_POST['message'];

if( $contact_name == true )
{
    $sender = $contact_email;
    $receiver = "putyour email here@hotmail.com";
    $client_ip = $_SERVER['REMOTE_ADDR'];
    $email_body = "Name: $contact_name \nEmail: $sender \n\nSubject: $contact_subject \n\nMessage: \n\n$contact_message \n\nIP: $client_ip \n\nContact Form by http://www.webworld.x10hosting.com";        
    $extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

    if( mail( $receiver, "BRIGHT DIGITAL STUDIO-CONTACT FORM- $contact_subject", $email_body, $extra ) ) 
    {
        echo "YOUR MESSAGE WAS SEND SUCCESSFULLY";
    }
    else
    {
        echo "YOUR MESSAGE WAS NOT SEND, PLEASE TRY AGAIN";
    }
}
?>
I hope now nobody can blame "x10hosting" for this reason....

If anybody needs further help please contact me.
http://www.webworld.x10hosting.com/
 
Top