php
2010-05-25 14 views 5 likes 
5

Ho il seguente codicecome cambiare impostazione predefinita inviato da: indirizzo di posta elettronica in php()

$subject = "Subject Here"; 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
// Additional headers  
$headers .= 'From: Domain Name <[email protected]>' . "\r\n";   
$to = $email; 
$body = ' 
My Message here 
'; 
mail($to, $subject, $body, $headers); 

ed inviare correttamente la posta, ma quando vedo i dettagli nella e-mail in Gmail ... si vede

dal Domain Name a [email protected]~~V~~3rd data mar 25 maggio, 2010 alle 12:41 soggetto il mio argomento qui mail-by mars.myhostingcompany.net

mentre voglio mostrare il mio indirizzo in mail per sezione in modo che dovrebbe essere mydomain.com invece di mars.myhostingcompany.net

risposta

4

Suppongo che tu sia su hosting condiviso quindi il motivo mostra l'indirizzo email del tuo host è perché quando si configura PHP c'è un ambiente chiamato "sendmail_from" che è un indirizzo predefinito per inviare la posta tramite nel caso in cui nessun indirizzo è previsto nel codice.

in cui sembra essere specificando le intestazioni corrette nel codice quindi posso solo pensare a una possibilità (che non posso provare da questo computer). Prova a rimuovere il <> intorno al vostro indirizzo di posta elettronica - si può tentare di leggere che, come HTML e quindi non hai nulla. Questa situazione può verificarsi su macchine Windows, perché lo stesso PHP analizza le intestazioni e non l'MTA (agente di trasferimento messaggi) e PHP tratta qualsiasi <> come HTML.

Mi rendo conto che non sembra professionale (dal momento che il client di posta elettronica non mostra il nome quando riceve l'e-mail) ma se si sta eseguendo da una macchina Windows c'è ben poco altro che si possa fare a meno che non si passare a un pacchetto di posta alternativo.

$subject = "Subject Here"; 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
// Additional headers  
$headers .= 'From: [email protected]' . "\r\n";   
$to = $email; 
$body = ' 
My Message here 
'; 
mail($to, $subject, $body, $headers); 
+0

Questo non deve essere contrassegnato come la risposta corretta. È completamente falso. Ho trovato questo tramite Google quindi sentivo che avevo bisogno di aggiungere questo commento - voglio dire senza offesa per voi @Jarrod. Ho aggiunto una risposta corretta. – LeonardChallis

+0

@LeonardChallis Si dovrebbe modificare la risposta allora. Le risposte tardive non vengono quasi mai accettate in seguito. : / –

0

// FORMA PAGE:

<form method="POST" action="mailer.php"> 
    <p>Please feel free to contact me on the form below or my direct email address: [email protected]<br> 
     <br><br> 
     <br> 
     <br> 
     <br> 
    </p> 
    <table width="327" border="0"> 
     <tr> 
     <td width="102">Name:</td> 
     <td width="215"><input type="text" name="name" size="19"></td> 
     </tr> 
     <tr> 
     <td>Company: 
     <label for="company"></label></td> 
     <td><input type="text" name="company"></td> 
     </tr> 
     <tr> 
     <td>Email: </td> 
     <td><input type="text" name="email" size="19"></td> 
     </tr> 
     <tr> 
     <td>Telephone No: 
     <label for="telephone"></label></td> 
     <td><input type="text" name="telephone"></td> 
     </tr> 
    </table> 
    <p><br> 
     Enquiry:<br> 
     <textarea rows="9" name="message" cols="65"></textarea> 
     <br> 
     <br> 
     <input type="submit" value="Submit" name="submit"> 
    </p> 
</form> 

// PHP MAILER PAGE

<?php 
if(isset($_POST['submit'])) { 

//SEND TO 
// Send the completed form to the below email address: 
    $to = "[email protected]"; 

//SUBJECT 
// Subject of the email form: 
    $subject = "Jason Kench - Web Developer"; 

//NAME 
//POST the details entered into the name box 
    $name = $_POST['name']; 
//COMPANY NAME 
// 
    $company = $_POST['company']; 
//EMAIL 
// 

    $email = $_POST['email']; 
//TELEPHONE NUMBER 
// 
    $telephone = $_POST['telephone']; 
//MESSAGE/ENQUIRY 
    $message = $_POST['message']; 

//Headers from a online site may help not sure 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
//FROM EMAIL ADDRESS: 

// Additional headers to change the FROM EMAIL ADDRESS 
$headers .= 'From: [email protected]' . "\r\n";   



// BODY 
// This is the body of the message that will be sent to my email address with their details. 
    $body = " 
    You have received a message from the online contact form at http://www.jasonkench.co.uk\n 
    Details Below: \n \n 
    From: $name\n 
    Company: $company\n 
    $headers 
    Email Address: $email\n 
    Telephone No: $telephone\n 
    Message: $message\n"; 
// FORM SENT 
// This will alert the customer the form has been successfully sent. 
    echo "Your details have been sent, I will contact you within 48 hours."; 
// Use the mail function to email the following variables to my $to email address. 
    mail($to, $subject, $body, $headers); 

} else { 
    // Display error message if there is a problem. 
    echo "Sorry there seems to be a problem. Please email me direct at: $to thank you."; 
} 
?> 
4

Esistono due tipi di mittente (Da), il mittente MIME intestazione e il envelope mittente.

si invia al mittente con MIME nelle intestazioni nel 4 ° parametro della funzione mail(). Stai facendo bene.

Il enveloper mittente (quello è possibile inviare l'invio di e-mail tramite sendmail o un wrapper sendmail compatibili) con il flag -f, si trova nel 5 ° mail() parametro, additional_parameters, nel formato che ci si passa sul comando riga: [email protected].

Così la vostra funzione di posta elettronica finirebbe per assomigliare a questo:

mail($to, $subject, $body, $headers, "[email protected]"); 
Problemi correlati