Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Problem sa PHP mail() funkcijom

[es] :: PHP :: Problem sa PHP mail() funkcijom

[ Pregleda: 1481 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

KDane
AJN

Član broj: 301350
Poruke: 16
*.javnenabavke.gov.ba.



Profil

icon Problem sa PHP mail() funkcijom18.02.2013. u 14:15 - pre 135 meseci
Ovako imam problem sa PHP mail() funkcijom na serverima gdje hostam web stranicu. Dakle ti serveri ne propuštaju ovu funkciju, odnosno mail poslan sa kontakt forme web stranice nikada ne dođe na specificiranu adresu. Admin kuće u kojoj plaćamo usluge hostinga mi je rekao da je to kod njih iz sigurnosnih razloga zabranjeno i da koristim smtp autentifikaciju.

Imam seljedeći kod koji radi sasvim dobro na drugim serverima, ali mi treba da radi i na ovom koji traži smtp autentifikaciju. Molim da mi pomognete kako da ubacim i taj dio u sljedeći kod:

Code:

<?php
//include the connection file
require_once('connection.php');

//save the data on the DB and send the email
if(isset($_POST['action']) && $_POST['action'] == 'submitform')
{
    //recieve the variables
    
    $name = $_POST['name'];
    $email = $_POST['email'];
    $title = $_POST['title'];
    $comment = $_POST['comment'];
    $ip = gethostbyname($_SERVER['REMOTE_ADDR']);
    
    //save the data on the DB
    
    mysql_select_db($database_connection, $connection);
    
    $insert_query = sprintf("INSERT INTO contacts (name, email, title, comment, date, ip) VALUES (%s, %s, %s, %s, NOW(), %s)",
                            sanitize($name, "text"),
                            sanitize($email, "text"),
                            sanitize($title, "text"),
                            sanitize($comment, "text"),
                            sanitize($ip, "text"));
    
    $result = mysql_query($insert_query, $connection) or die(mysql_error());
    
    if($result)
    {
        //send the email
        
        $to = "[email protected]";
        $subject = "New contact from the website";
        
        
        //headers and subject
        $headers  = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= "From: ".$name." <".$email.">\r\n";
        
        $body = "New contact<br />";
        $body .= "Name: ".$name."<br />";
        $body .= "Email: ".$email."<br />";
        $body .= "Comment: ".$comment."<br />";
        $body .= "IP: ".$ip."<br />";
        
        mail($to, $subject, $body, $headers);
        
        //ok message
        
        echo "Your message has been sent";
    }
}

function sanitize($value, $type) 
{
  $value = (!get_magic_quotes_gpc()) ? addslashes($value) : $value;

  switch ($type) {
    case "text":
      $value = ($value != "") ? "'" . $value . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $value = ($value != "") ? intval($value) : "NULL";
      break;
    case "double":
      $value = ($value != "") ? "'" . doubleval($value) . "'" : "NULL";
      break;
    case "date":
      $value = ($value != "") ? "'" . $value . "'" : "NULL";
      break;
  }
  
  return $value;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TheTechLabs.com - PHP form mail Tutorial</title>
</head>
<body>

<form id="contact" name="contact" action="contact.php" method="post">
<p><label>Name: <input type="text" id="name" name="name" value="" /></label></p>
<p><label>Email: <input type="text" id="email" name="email" value="" /></label></p>
<p><label>Website: <input type="text" id="title" name="title" value="" /></label></p>
<p><label>Comment:<br /><textarea id="comment" name="comment"></textarea></label></p>
<input type="hidden" id="action" name="action" value="submitform" />
<p><input type="submit" id="submit" name="submit" value="Submit" /> <input type="reset" id="reset" name="reset" value="Reset" /></p>
</form>
</body>
</html>
 
Odgovor na temu

duskooo
BG

Član broj: 52174
Poruke: 44
*.adsl-a-1.sezampro.rs.



+1 Profil

icon Re: Problem sa PHP mail() funkcijom18.02.2013. u 21:11 - pre 135 meseci
SMTP autentifikacija iz PHP-a (primer).
 
Odgovor na temu

gotivac
Kragujevac

Član broj: 26754
Poruke: 160
*.dynamic.sbb.rs.



+2 Profil

icon Re: Problem sa PHP mail() funkcijom22.02.2013. u 15:37 - pre 135 meseci
Ako baš hoćeš da se zajebavaš sa PEAR-om, evo ti ovde objašnjeno, pogledaj i poruke pre ove, ali u ovoj je konačno uputstvo koje radi.

Ali bih ti svakako preporučio phpmailer.
 
Odgovor na temu

[es] :: PHP :: Problem sa PHP mail() funkcijom

[ Pregleda: 1481 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.