{"id":151,"date":"2009-07-21T18:36:03","date_gmt":"2009-07-21T13:06:03","guid":{"rendered":"http:\/\/vikku.info\/codesnippets\/?p=151"},"modified":"2009-07-21T18:44:23","modified_gmt":"2009-07-21T13:14:23","slug":"sending-mail-from-localhost-in-php","status":"publish","type":"post","link":"http:\/\/vikku.info\/codesnippets\/php\/sending-mail-from-localhost-in-php\/","title":{"rendered":"sending mail from localhost in php"},"content":{"rendered":"<p>Use the basic phpmailer code which comes with the phpmailer zip form phpclasses.org<br \/>\nthe following code is the default one which sends mail from your server by using the default server settings.<\/p>\n<p>the host name is set to localhost and authentication is false(which takes the default). these are the two lines which<br \/>\nvary when sending mail form localhost. <\/p>\n<pre lang=\"php\">\r\ninclude(\"includes\/phpmailer\/class.phpmailer.php\");\r\n\r\n$mail = new phpmailer();\r\n$mail->PluginDir = \"\/include\/\";\r\n$mail->IsSMTP(); \/\/ send via SMTP\r\n\r\n$mail->From = \"noreplysample.com\";\r\n$mail->FromName = \"From Name\";\r\n$mail->AddAddress(\"address@host.com\");\r\n$mail->WordWrap = 65; \/\/ set word wrap\r\n$mail->IsHTML(true); \/\/ send as HTML\r\n$mail->Subject = \"Mail Subject\";\r\n\r\n$mail->SMTPAuth = false; \/\/ turn off SMTP authentication\t\t\t\r\n$mail->Host = \"localhost\"; \/\/ SMTP servers\r\n\r\n$mail->Body = $msg;\r\n$mail->send();\r\n\r\n<\/pre>\n<p>the code to send mail form your localhost to any remote email server<br \/>\nthe difference in the above and the following is i have given the important part which need to send mail from localhost<br \/>\nthe first below two lines differ from the above. and the last two lines are added.<br \/>\nyou have to give your servers auth information to send mail. So when ever mail is sent from localhost to a remote server<br \/>\na server reference is needed. which means&#8230; mail is sent form localhost on-behalf of your server.<\/p>\n<pre lang=\"php\">\r\n\r\n$mail->SMTPAuth = true; \/\/ turn on SMTP authentication\r\n$mail->Host = \"samplesite.com\"; \/\/ SMTP servers\r\n$mail->Userame = \"testing@testing.com\";\r\n$mail->Password = \"testing\";\r\n<\/pre>\n<p>so when the above lines gets executed this code connects to your site for verification<br \/>\nand then the mail is sent with reference to your server. so<br \/>\nyou need a server by using which you can send mails from localhost.<\/p>\n<p>here is the full code which sends mail from localhost.<\/p>\n<pre lang=\"php\">\r\ninclude(\"includes\/phpmailer\/class.phpmailer.php\");\r\n\r\n$mail = new phpmailer();\r\n$mail->PluginDir = \"\/include\/\";\r\n$mail->IsSMTP(); \/\/ send via SMTP\r\n\r\n$mail->From = \"noreplysample.com\";\r\n$mail->FromName = \"From Name\";\r\n$mail->AddAddress(\"address@host.com\");\r\n$mail->WordWrap = 65; \/\/ set word wrap\r\n$mail->IsHTML(true); \/\/ send as HTML\r\n$mail->Subject = \"Mail Subject\";\r\n\r\n$mail->SMTPAuth = true; \t\t\t\t\t\t\r\n$mail->Host = \"samplesite.com\"; \/\/ SMTP servers\r\n$mail->Userame = \"testing@samplesite.com\";\r\n$mail->Password = \"testing\";\r\n\r\n$mail->Body = $msg;\r\n$mail->send();\r\n<\/pre>\n<p>the from address should be a valid domain string. else mostly your mail will not be sent.<\/p>\n<p>&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use the basic phpmailer code which comes with the phpmailer zip form phpclasses.org the following code is the default one which sends mail from your server by using the default server settings. the host name is set to localhost and authentication is false(which takes the default). these are the two lines which vary when sending [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/151"}],"collection":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":7,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":158,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/151\/revisions\/158"}],"wp:attachment":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}