Jump to content

how do i use phpmailer in host(in internet)


sonita

Recommended Posts

hi

i create a contact form,and write with mail() function.my host don't support this function and i must to use

phpmailer in my contact's page code.but i don't know phpmailer? and i don't know how do i that in my contact page?

i know,i must to change mycode in contact page,but i don't know how do i?

please help me. & explain me for a example

Link to comment
Share on other sites

hello

this code is a my contact page's code & i use mail() function but myhost don't support this function and don't send Email to myemail address(info@keivanstone.ir)

my host support phpmailer only

  <?php//session_start(); #was missing//ini_set("display_errors",1); #remove this on production, needed it to see any errors$php_self = $_SERVER['PHP_SELF'];//$error_name = " you don't enter name.please enter you name.";// on submit$mail_sent=0;$error_name = $error_email = $error_subject=$error_body = $error_captcha = '';if( isset($_POST['name']) && isset($_POST['email'])&&isset($_POST['subject']) && isset($_POST['body']) && isset($_POST['captcha']) ){    $name = $_POST['name'];    $email = $_POST['email'];	$subject = $_POST['subject'];    $body = $_POST['body'];    $captcha = $_POST['captcha'];	    $error = 0;    // name    if( $name == "" ){ $error=1; $error_name = "class='error'"; }    // email    if( $email == "" ){ $error=2; $error_email = "class='error'"; } 	// subject    if( $subject == "" ){ $error=3; $error_subject = "class='error'"; }    // body    if( $body == "" ){ $error=4; $error_body = "class='error'"; }    // captcha    if( $captcha == "" || $captcha != $_SESSION['captcha']){ $error=5; $error_captcha = "class='error'"; }       // no error, send email    if( $error == 0){                                                // your email address        $address = "info@keivanstone.ir";                   // email subject        $subject = "New body";        // email content        $content = "$name,$email,$body";        // html email$email_content = "<!doctype html><head><meta charset='utf-8'><title>".$subject."</title>";        $email_content .= "</head><body>";        $email_content .= $content;        $email_content .= "</body></html>";                                              // headers for html email        $headers  = 'MIME-Version: 1.0' . "/r/n";        $headers .= 'Content-type: text/html; charset=utf-8' . "/r/n";        $headers .= "From: info@keivanstone.ir" . "/r/n";        // send email        mail($address, $subject, $email_content, $headers);                          // reset variables        $name = ""; $email = ""; $body = "";        $mail_sent = 1;                                                               }}else{    $name = $email = $subject= $body = $captcha = ''; }// captcha$num = rand(1, 40);$num2 = rand(5, 25);   $verif = $num . "+" . $num2;$_SESSION['captcha'] = $num + $num2;       if( $mail_sent == 1 ){    echo "<h4>از تماس شما سپاسگزاریم.<br/>تا48 ساعت آینده پاسخ خود را دریافت خواهید کرد.<br/>گروه سنگ آنتیک کیوان</h4>";} else {    echo "    <form action='".$php_self."' method='post'>    <p><label for='name'>نام:</label> <span class='required'>*</span></p>    <input type='text' ".$error_name." name='name' value='".$name."'>    <p><lable for='email'>پست الکترونیک:</label> <span class='required'>*</span></p>    <input type='text' ".$error_email." name='email' value='".$email."'>  	<p><label for='subject'>موضوع:</label> <span class='required'>*</span></p>    <input type='text' ".$error_subject." name='subject' value='".$subject."'>    <p><label for='body'>پیام شما:</label> <span class='required'>*</span></p>    <textarea ".$error_body." id='body' name='body' style='width:460px;height:119px;'>".$body."</textarea>    <p><label>جمع دوعدد:".$verif."?</label> <span class='required'>*</span></p>              <input type='text' ".$error_captcha."  id='captcha' name='captcha' value=''><br/>     <input type='submit' value='ارسال'/>    </form>";}?>

i must change above code & replace with phpmailer...

More questions in the next post I write.

Edited by sonita
Link to comment
Share on other sites

i know below code is a class.phpmailer.php , and i must to use this code and create a new object of this class

<?phpclass Emailer{	private $sender;	private $recipients;	private $subject;	private $body;	 public function __construct($sender){	 $this->sender=$sender;	 $this->recipients=array(); } public function AddRecipients($recipients){	array_push($this->recipients,$recipients); } public function SetSubject($subject){	 $this->subject=$subject; } public function SetBody($body){	$this->body=$body;  } public function SendEmail(){	 foreach($this->recipients as $recipient){		 $result=mail($recipient,$this->subject,$this->body,"From: {$this->sender}rn");		 if($result){			echo "Mail successfully sent to {$recipient}<br/>".PHP_EOL; 		 }	 }   }}?>

but i don'tknow how do i change contactpage 's code ?& how do i write mycontact page with phpmailer?

Mail server and authentication issues that I put into it,
I also wanted to be able to send email.
please help me -_- very very important because myweb is in the internet....
Edited by sonita
Link to comment
Share on other sites

sorry ,i can't mail() function in the my contact page with phpmailer.

please more explain me.

i read & see above link,but i don't undrestand.

how do i replace phpmailer function with mail() function a contact page's code?

 

please help me.

Link to comment
Share on other sites

which part don't you get? what have you tried?

 

All those links are examples of using the PHPMailer class, as defined by your requirements. Did you follow any of those examples to actually use the class to send mail?

 

Show us what you've tried and what errors/problems you are getting and then we can try and help you through it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...